Computer Science, asked by chowdaryrupa93, 10 months ago

Consider the following operation performed on a stack of size 5.Push(10);Pop();Push(20);Push(32);Pop();Push(45);Pop();Pop();Push(57);After the completion of all operation, the number of elements present in stack are *

Answers

Answered by BrainlyYoda
5

Answer:

Stack size => 5.

It means that stack can store maximum 5 elements.

Stack containing elements => 0, 0, 0, 0, 0

Operations performed =>

Push(10); => 10 is pushed into stack.

Stack containing elements => 10, 0, 0, 0, 0

Pop(); => 10 is removed from stack.

Stack containing elements => 0, 0, 0, 0, 0

Push(20); => 20 is added into stack.

Stack containing elements => 20, 0, 0, 0, 0

Push(32); => 32 is added into stack.

Stack containing elements => 20, 32, 0, 0, 0

Pop(); => Last element filled which is 32 will get removed from stack.

Stack containing elements => 20, 0, 0, 0, 0

Push(45); => 45 is added into stack.

Stack containing elements => 20, 45, 0, 0, 0

Pop(); => Last element filled which is 45 will get removed from stack.

Stack containing elements => 20, 0, 0, 0, 0

Pop(); => Last element filled which is 20 will get removed from stack.

Stack containing elements => 0, 0, 0, 0, 0

Push(57); => 57 is added into stack.

Stack containing elements => 57, 0, 0, 0, 0

The numbers of elements present in stack after completion of operations is 1 which is 57.

When a stack size is defined and nothing is added into the stack then it is called as empty stack and every place is initialised with 0.

Push operation adds element to stack

Pop operation removes the last element added to stack.

Answered by topwriters
4

One element - 57

Explanation:

Stack size is 5.

Operation  Elements Present in stack

Push (10)      10

Pop ()         Empty

Push (20)      20

Push (32)      20 , 32

Pop ()            20

Push (45)      20, 45

 Pop ()          20

Pop ()           Empty

Push (57)      57

At the end, the only element present in stack is 57. So answer is one.

Similar questions