Professional Documents
Culture Documents
Tutorial 03
2. Describe how the following set of operations work on the code written by you above. You
may use a suitable diagram to illustrate the answer.
1. Push(‘a’)
2. Push(‘b’)
3. Push(‘c’)
4. Pop
5. Push(‘d’)
6. Pop
7. Pop
8. Pop
9. Push(‘e’)
Input: Q = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
Output: Q = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
Input: [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
4. Given an efficient circular array-based queue (Q) capable of holding 10 objects. Show the
Begin
Initialize Stacks S1 and S2
Push all inputs into Stack S1
Procedure P () {
While (! s1.isempty ())
Push S2 (Pop S1 ())
}
While (! s2.isempty ())
Print (pop S2 ())
End
6. Write a pseudo code algorithm and c program to generate binary numbers between 0 to
n using a queue
8. What are the two problems associated with the linear queue?
9. Write an algorithm to delete an element from a circular queue.
10. Write a pseudo code algorithm to Implement a Queue using two Stacks.