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()
{
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;

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;
}
``````

Say you have two lists with nodes at addresses a, b, c, d with a pointing to b and c pointing to d: a->b and c->d. To addend c->d to a->b point b to c using b->next == c and d comes along for free.

To add the values in c->d to a->b you cycle through c->d using new nodes to hold the values and add each new node to a->b. The a->b list is changed but the c->d list isn't.

If you want to maintain both initial lists then create a third list using new nodes to hold the value of each node from each list you want to combine.