Computer Science, asked by onkarlokhande143, 6 months ago

initially stack is empty stack is allocated n=6 memory cell find output

Answers

Answered by dreamrob
8

Complete question is : Suppose STACK is allocated N=6 memory cells and initially STACK is empty, or, in other words, TOP = 0.

Find the output of the following module:

1. Set AAA:=2 and BBB:=5.  

2. Call PUSH(STACK, AAA).

Call PUSH(STACK, 4).

Call PUSH(STACK, BBB+2).

Call PUSH(STACK, 9).

Call PUSH(STACK, AAA+BBB).

3. Repeat while TOP!=0;

Call POP(STACK, ITEM).

Write: ITEM.

[End of loop]

4. Return

Solution :

Dry Run :

Since STACK follows the concept of Last In First Out (LIFO)

In Stack we Push elements from bottom to top and we Pop elements from top to bottom.

1) AAA = 2 , BBB = 5

2) Call PUSH(STACK, AAA)

Value at 0th index = 2

Call PUSH(STACK, 4)

Value at 1st index = 4

Call PUSH(STACK, BBB+2)

Value at 2nd index = 5+2 = 7

Call PUSH(STACK, 9)

Value at 3rd index = 9

Call PUSH(STACK, AAA+BBB)

Value at 4th index = 2+5 = 7

OUTPUT : 7 9 7 4 2

Answered by vinod04jangid
0

Answer:

OUTPUT : 7 9 7 4 2

Explanation:

1) AAA = 2 , BBB = 5

2) Call PUSH(STACK, AAA)

Value at 0th index = 2

Call PUSH(STACK, 4)

Value at 1st index = 4

Call PUSH(STACK, BBB+2)

Value at 2nd index = 5+2 = 7

Call PUSH(STACK, 9)

Value at 3rd index = 9

Call PUSH(STACK, AAA+BBB)

Value at 4th index = 2+5 = 7

OUTPUT : 7 9 7 4 2

#SPJ2

Similar questions