Implementing Queue Using Stack
Two approaches
1) Using Multiple Stacks
Input:
enque(4)
dequeue()
enque(2)
dequeue()
enque(7)
dequeue()
Output:
1: 4
2: 2
3: 7
2) Using Single Stack and Recursive Method
Input:
enque(4)
dequeue()
enque(8)
enque(2)
dequeue()
enque(7)
dequeue()
Output:
1: 4
2: 2
3: 7
4: 8
Two approaches
1) Using Multiple Stacks
Input:
enque(4)
dequeue()
enque(2)
dequeue()
enque(7)
dequeue()
Output:
1: 4
2: 2
3: 7
2) Using Single Stack and Recursive Method
Input:
enque(4)
dequeue()
enque(8)
enque(2)
dequeue()
enque(7)
dequeue()
Output:
1: 4
2: 2
3: 7
4: 8
No comments:
Post a Comment