Problem

Add a method si ze() to both Stack (PROGRAM 4.3.4) and Queue (PROGRAM 4.3.6) that returns...

Add a method si ze() to both Stack (PROGRAM 4.3.4) and Queue (PROGRAM 4.3.6) that returns the number of items in the collection. Hint: Make sure that your method takes constant time by maintaining an instance variable n that you initialize to 0, increment in push() and enqueue(), decrement in pop() and dequeue (), and return in size().

Program 4.3.4 Generic stack

Program 4.3.6 Generic FIFO queue (linked list)

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search