Combining queue and stack link list?
hello so here is my question i ave to connect a link lists together, one who behaves like a stack the other like a queue.the numbers used are 11 22 44 77 33 99 66.
so the stack link list looks like this 66 99 33 77 44 22 11
queue link list looks like this 11 22 44 77 33 99 66
what i need to do is combine both, connect the stack to the queue to make a new link list with 14 numbers.
new link list should look like this 66 99 33 77 44 22 11 11 22 44 77 33 99 66
also i need to find the average of all numbers and how many numbers are above average.
this is what i have so far, it does not want to output the new link list. would greatly appreciate the help.
#include <iostream>
using namespace std;
struct NODE
{
int info;
NODE *next;
};
NODE *Queue;
NODE *Stack;
NODE *t;
NODE *rear;
int main()
{
//ask user to enter numbers in Stack link list.
Stack=NULL;
for(int i=0; i<=6; ++i)
{
t=new(NODE);
cout<<"Enter a number:"; cin>>t->info;
t->next=Stack;
Stack=t;
}
//displays the nodes in the Stack link list.
t=Stack;
while(t!=NULL)
{
cout<<t->info<<'\t';
t=t->next;
}
cout<<endl;
//ask user to enter numbers in Queue 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;
//connects the stack to the queue to make new list
t=Stack;
while(t->next!=NULL)
{
t=t->next;
t->next=Queue;
}
//displays the numbers from new link list
t=Queue=Stack;
while(t!=NULL)
{
cout<<t->info<<'\t';
t=t->next;
}
cout<<endl;
//find the average of all numbers
int total=0;
t=Queue=Stack;
while(t!=NULL)
{
total +=t->info;
t=t->next;
}
int average=0;
int totalNodes=14;
t=Queue=Stack;
while(t!=NULL)
{
average=total/totalNodes;
}
cout<<"Average of the numbers is "<<average;
return 0;
}