Rewrite ENQUEUE and DEQUEUE

173 views 8:43 am 0 Comments August 5, 2023


1. Rewrite ENQUEUE and DEQUEUE to detect underflow and overflow of a queue.

2. Whereas a stack allows insertion and deletion of elements at only one end, and a queue allows insertion at one end and deletion at the other end, a deque (double ended queue) allows insertion and deletion at both ends. Write four O(1)-time procedures to insert elements into and delete elements from both ends of a deque implemented by an array.

3. Show how to implement a queue using two stacks. Analyze the running time of the queue operations.

4. Show how to implement a stack using two queues. Analyze the running time of the stack operations.

Tags: , , , , , , ,