**BIO303 Midterm Short Questions By Freshsweb.com**

At the beginning, the stack is empty. First, we push the value 2 onto the stack. Like

resulting in the number 2 being placed on the stack. We have a top pointer that points up

element. Then we said push(5). Now look at how the 2 and 5 are stacked. The number 5 is

placed at the top of the number 2 and the top of the pointer moves up one step. Then we are

he pressed the number 7 which is placed at the top and the number 2 and 5 are at the bottom.

Similarly, we press the number 1. The last image in the first line shows the stacked values

of numbers – 1, 7, 5 and 2.

You may like: CS304 FINAL TERM SOLVED PAPERS /MOAAZ By freshsweb.com

We remove the elements from the stack. The first picture of the second row shows pop

act. As a result, the number 1 pops up. After that, we press the number 21 again

stack. Numbers 7, 5 and 2 are already in the stack and number 21 is being pushed

top. If we jump now, the number 21 is dropped. Now number 7 is on top. If we did

pop again, number 7 is cracked. Pop again and the number 5 will appear and the number

2 remains in the stack. Here with the help of this diagram we prove that

values are added at the top and removed from the top of the stack.

**BIO303 Midterm Short Questions By Freshsweb.com**

The last element to go on the stack is the first to come off. That’s why the stack

known as LIFO (Last In First Out) structure. We know that the last element has been squeezed in

the stack is on top, which is removed when we call pop. Let’s look at the next one

scenarios. What happens if we call pop() when there is no element? One possible

the way out is that we have a isEmpty() function that returns true if the stack is empty and false

Otherwise. This is a boolean function that returns true if there is no element in the file

stack. Otherwise, it returns false. The second possibility is that if we call pop

throws an exception on an empty stack. This is an advanced C++ concept.

Exception is also a way to communicate that some unusual condition or

something went wrong. Suppose we have a divide method and try to divide

some number with zero. This method throws a “divide by zero” exception.