Skip to content

Files

Latest commit

 

History

History

QueueReversal

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

The idea is to Reverse a Queue using a Stack

Queue works in the FIFO fashion Stacks works in - LIFO fashion

you have some Queue let say = q1

1 --> 2 --> 3 --> 4

Reverse : 4 --> 3 --> 2 --> 1

  1. pop all the elements from the q1
  2. push poped elements into the Stack s1
  3. Now the q1 will be empty
  4. Pop all the elements from the Stack s1 till it become empty
  5. place the poped elements back into the Queue q1