Question: Java The size of a LinkedStack is an integer that identifies the number of nodes in a LinkedStack. Write a recursive method called sizeRec for
Java
The size of a LinkedStack is an integer that identifies the number of nodes in a LinkedStack. Write a recursive method called sizeRec for the LinkedStack class that returns the size of the LinkedStack. Write an iterative method called sizeIter for the LinkedStack class that returns the size of the LinkedStack. Create a driver to test both of these methods on the following cases: 1) The LinkedStack is empty. Check the size. 2) The LinkedStack has 5 elements in it. Check the size. 3) The LinkedStack has 1 element in it. Check the size. Pop the element and check the size again. What is the runtime of these methods? How could the LinkedStack data structure be modified so that the size method was constant time? (Give the answers in your comment region at the top of the driver program.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
