1. Suppose an initially empty stack S has performed a total of 25 push operations, 12 top operations, and 10 pop operations, 3 of which returned null to indicate an empty stack. What is the current size of S?
2. Suppose an initally empty queue Q has performed a total of 32 enqueue operations, 10 first operations, and 15 dequeue operations, 5 of which returned null to indicate an empty queue. What is the current size of Q?
1) For stack:
- Push – adds item to collection and increases size of stack
- Top – only returns last item from collection without removing it
- Pop – returns last item from collection and decrease size of stack
If 3 pop operations returned null then only 7 pop operations decrease size of stack. Current size of stack is 25 (push) - 7 = 18;
2) For queue:
- enqueue – adds item to collection and increases size of queue
- first – only first last item from collection without removing it
- dequeue – returns first item from collection and decrease size of stack
The same is for queue : Current size of queue is -> 32 – 10 = 22.
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!