Question: #42 And #46 all parts Create a toString method for the LinkedStack class. This method should create and return a string that correctly represents the

#42 And #46 all parts

 #42 And #46 all parts Create a toString method for the

Create a toString method for the LinkedStack class. This method should create and return a string that correctly represents the current stack. Such a method could prove useful for testing and debugging the LinkedStack class and for testing and debugging applications that use the LinkedStack class. Suppose decide to add new operation to our Stack called sizeIs, which returns a value of primitive type int equal to the number of items on the stack. The method signature for sizeIs is public int sizeIs() a. Write the code for sizeIs for the Array Stack class. b. Write the code for sizeIs for the Linked Stack class (do not add any instance variables to the class: each time sizeIs is called you must "walk" through the stack and count the nodes.) c. Suppose you decide to augment the LinkedStack class with an instance variable size that always holds the current size of the stack. Now you can implement the sizeIs operation by just returning the value of size. Identify all of the methods of LinkedStack that you need to modify to maintain the correct value in the size variable and describe how you would change them. d. Analyze the methods created/changed in parts a, b, and c in terms of Big-O efficiency

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!