Abstract Data Types Read pages 249 and 250 and answer the qu

Abstract Data Types Read pages 249 and 250 and answer the questions. Do not use direct quotes from the text, but make it clear that you have read the text to answer the questions.

a) Suppose the following data is made available to the algorithm on page 249: 1 2 3 4 5. What gets written by executing the algorithm?

b) Answer the same question for the algorithm on page 250.

Solution

Stack is a collection of data which inserts data and remove data in LIFO(Last In First Out) behaviour.

Stack basically has two operations PUSH and POP.

PUSH - Insert operation.

POP - Delete operation. (Delete element that was last pushed into the stack.

so Algorithm on Page no - 249.

it reads all the data and push into the stack. Input given 1,2,3,4,5.

So now stack has 1,2,3,4,5.

second while loop checks whether stack is empty or not and delete element until stack is empty.

so the result will be 5,4,3,2,1 according to LIFO.

Queue: contains data and delete data in FIFO (First In First Out).

Enque is same as PUSH and Deque is same as POP.

So According to FIFO result will be 1,2,3,4,5.

Abstract Data Types Read pages 249 and 250 and answer the questions. Do not use direct quotes from the text, but make it clear that you have read the text to an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site