Answer to Question #4377 in C++ for sya
2011-10-04T13:01:20-04:00
TASK 3 [20 marks]
Write a program that will accept a list of integer number. The odd numbers will be stored into a queue call ODDQUEUE and the even number will be stored in different queue call EVENQUEUE
1
2011-10-06T09:36:51-0400
#include <stdlib.h> #include <stdio.h> struct Node { & int Num; & Node* Next; } *Odd, *Even; & Node P; Node* Create(int Num) { & P.Num=Num; & P.Next=NULL; & return &P; } Node* Add(Node* End, int Num) { & End->Next=(Node*)malloc(sizeof(Node)); & End=End->Next; & End->Num=Num; & End->Next=NULL; & return End; } void PrintList(Node *H) { & printf("\n"); & while(H!=NULL) & { & printf("%d ",H->Num); & H=H->Next; & } } int main(int argc, char *argv[]) { Even=Odd=NULL; Node* EEnd=NULL,*OEnd=NULL; int N,i=0; while(i==0) { & scanf("%d",&N); & if(N%2==0) & { if(Even==NULL) { Even=Create(N); EEnd=Even; } else { EEnd=Add(EEnd,N); } & } & else & { if(Odd==NULL) { Odd=Create(N); OEnd=Odd; } else { OEnd=Add(OEnd,N); } & } } system("PAUSE"); return EXIT_SUCCESS; }
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
C++
Comments
Leave a comment