How to display odd and even numbers from a queue link list?
hello everyone i really need some help right now on this program. what this program is supposed to do is copy 11 22 44 77 33 99 66 into a linked list that behaves like a queue. the program should display the queue, display the odd numbers, display the even numbers.
display queue should look like this 11 22 44 77 33 99 66
display odd numbers should look like this 11 77 33 99
display even numbers should look like this 22 44 66
so far i can only display the queue with the program i have so far and odd and even numbers do not show up at all. here is my program would really appreciate the help. thanks to whomever can help me. also the way i got the queue link list to display is there a better way to do it or is it ok how i did it.
#include <iostream>
using namespace std;
struct NODE
{
int info;
NODE *next;
};
NODE *Queue;
NODE *t;
NODE *rear;
int main()
{
//ask user to enter numbers in Stack link list.
Queue=rear=NULL;
for(int i=0; i<=6; ++i)
{
t=new(NODE);
cout<<"Enter a number:"; cin>>t->info;
t->next=Queue;
if(rear==NULL)
{
Queue=rear=t;
}
else
{
rear->next=t;
rear=t;
}
}
//displays the nodes in the Queue link list.
t=Queue;
for(int i=0; i<=6; ++i)
{
int x;
x=Queue->info;
Queue=Queue->next;
cout<<x<<'\t';
}
cout<<endl;
//finds and displays the odd numbers.
t=Queue;
while(t!=NULL)
{
if(t->info%2!=0)
t=t->next;
}
cout<<t<<'\t';
//finds and displays the even numbers.
t=Queue;
int EvenCounter=0;
while(t!=NULL)
{
if(t->info%2==0)
t=t->next;
}
cout<<t<<endl;
return 0;
}