Dsa Midterm
Dsa Midterm
Stacks are also used to implement A queue is a linear data structure Step 1: Check if the queue is empty.
the undo/redo operation in text that is open at both ends and the Step 2: If the queue is empty, return
editor. operations are performed in First In the underflow error and exit.
First Out (FIFO) order.
IMPLEMENTATION OF STACKS Step 3: If the queue is not empty,
We define a queue to be a list in access the data where the front is
A stack can be implemented using
which all additions to the list are pointing.
an array or a linked list.
made at one end, and all deletions
In an array-based implementation, from the list are made at the other Step 4: Increment the front pointer
the push operation is implemented end. The element which is first to point to the next available data
by incrementing the index of the pushed into the order, the delete element.
top element and storing the new operation is first performed on that. Step 5: The Return success.
element at that index.
This is a special type of queue program, there may be multiple
where the last position is connected requests to be kept in a queue, or
back to the first position. Here also one task may create other tasks,
the operations are performed in which must be done in turn by
FIFO order. keeping them in a queue.
• Implementation of Queue
Output Restricted Queue: using Arrays