Hi!I am trying to create a deque using these stacks but I failes again and again.If anyone can help:
struct deque {
int key;
dek *next;
} *left = NULL, *right=NULL;
struct elem{
int key;
elem *next;
} *start1=NULL,*start2=NULL,*p;
void add_1(int n) //Adds elements in the first stack
{
elem *p = start1;
start1 = new elem;
start1->key = n;
start1->next = p;
}
void add_2(int n) //Adds elements in the second stack
{
elem *p = start2;
start2 = new elem;
start2->key = n;
start2->next = p;
The structures are ok,I am trying to form a deque using the 2 stacks.I think it will be done by combining the elements that I add in the stacks
The problem is that the function,which forms the deque from the 2 stacks doesn`t work:
void build (int n)
{
elem * n1 = start1; //pointer to the first stack
elem* n2 = start2; //pointer to the second stack
while (n1 != NULL || n2 != NULL)
{
push_l(n);
n1 = n1->next;
push_r(n);
n2 = n2->next;
}
}