Today I am looking to make my own dequeue in c ++ using pointers. Well, in the program, I want to create two dequeues in which to add different elements. Unfortunately, this is not what happened. On screen i got 6 5 insted only 6. Why?I'm not sure exactly how to make two separate dequeues? I think one of my problems are *L = NULL, * R = NULL but i am not sure?
So my code so far -
#include <iostream>
struct elem
{
    int key;
    elem* next;
}*L = NULL, * R = NULL;
void push_l(int n, elem*& p)
{
    p = L;
    L = new elem;
    L->key = n;
    L->next = p;
    if (R == NULL)
        R = L;
}
int pop_l(int& n, elem*& p)
{
    if (L)
    {
        p = L;
        n = L->key;
        L = L->next;
        if (L == NULL)
            R = NULL;
        delete p;
        return 1;
    }
    else
    {
        return 0;
    }
}
int main()
{
    int k;
    elem* p = new elem;
    elem* q = new elem;
    push_l(5, p);
    push_l(6, q);
    while (pop_l(k, q))
    {
        std::cout << k<< " ";
    }
}
I am not sure how can i print only 6 on the screen because this element is only pushed to the dequeue ? Also these are just some of the features for dequeue because I want to understand it from the beginning !
 
    