olyska20 Posted October 25, 2008 Report Share Posted October 25, 2008 надо создать очередь. Вывести ее на экран. затем удалить с неё все элементы кратные 5 и снова вывести на экран. Я создала очередь но не могу удалить. Надо предусмотреть что числа, кратные 5 могут быть и в серелдине очереди и на конце. Это 2 случая. как это сделать прошу помочь. #include "stdafx.h" #include <stdio.h> #include <conio.h> struct Stack{ int info; Stack *ref; }; void MakeQueue() { Stack *beg, *end, *q; int i = 0; printf(" Filling queue: \n "); printf("Enter number: "); scanf("%d", &i); q = new Stack; q->ref = NULL; q->info = i; beg = end = q; while (i >= 0) { printf(" Enter number: "); scanf("%d", &i); q = new Stack; q->ref = NULL; q->info = i; end->ref = q; end = q; } printf("\n Taking from queue\n"); while (beg != NULL) { printf ("Element: %d\n", beg->info); q = beg->ref; delete beg; beg = q; } } int main(int argc, char* argv[]) { MakeQueue(); return 0; } Link to comment Share on other sites More sharing options...
Тролль Posted October 25, 2008 Report Share Posted October 25, 2008 (edited) #include <iostream.h>int main(){ struct Queue { struct Stack{int info; Stack *ref;}; Stack *beg, *end, *q; void into(int i) {q=new Stack; q->ref=NULL; q->info=i; end->ref=q; end=q;} int out(void) { if(beg->ref!=NULL) {int j=beg->ref->info; q=beg->ref; delete beg; beg=q; return j;} else return -1; } Queue(){q=new Stack; q->ref=NULL; q->info=0; beg=end=q;} };Queue q,p; int i;while(i>=0){cout<<" Enter number: "; cin>>i; if(i>=0)q.into(i);}cout<<endl; i=1; while(i>=0){i=q.out(); if(i>=0){cout<<i<<endl; if(i%5)p.into(i);}}cout<<endl; i=1; while(i>=0){i=p.out(); if(i>=0)cout<<i<<endl;}getchar(); getchar(); return 0;} Edited October 25, 2008 by Тролль Link to comment Share on other sites More sharing options...
olyska20 Posted October 26, 2008 Author Report Share Posted October 26, 2008 пасибо тебе огромное а то сижу и думаю как это сделать))) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now