Suppose an initially empty stack S has performed a total of 15 push operations, 12 top operations, and 13 pop operations ( 3 of which returned null to indicate an empty stack ). What is the current size of S

Respuesta :

Answer:

The current size is 5

Explanation:

From this question,

You popped a total of 13-3 = 10 elements (3 was subtracted because these 3 pops are null and does not change the size of the stack). Therefore only 10 does.

- A total of 15 elements were pushed

- top operations cannot change the size or state of the stack so we are to ignore this.

The current size of s is therefore

15-10

= 5 elements

Another way to calculate this is 15-(13-3) = 5