Stack/Stack implementation using two queue.cpp
// Insert an item into the stack
Insert an item into the stack
Insert an item into the stack
void push(int data)
{
        while (!q1.empty())
        {
            q2.push(q1.front());
            q1.pop();
        }
        q1.push(data);
        while (!q2.empty())
        {
            q1.push(q2.front());
            q2.pop();
        } 
}
void push ( int data ) { while ( ! q1 . empty ( ) ) { q2 . push ( q1 . front ( ) ) ; q1 . pop ( ) ; } q1 . push ( data ) ; while ( ! q2 . empty ( ) ) { q1 . push ( q2 . front ( ) ) ; q2 . pop ( ) ; } }
Insert an item into the stack
Insert an item into the stack
// Move all elements from the first queue to the second queue // Push the given item into the first queue // Move all elements back to the first queue from the second queue