Question: I need help with modifying my code on the left. We are using the textbook Data Structure and Algorithms using Java by William McCallister. public

 I need help with modifying my code on the left. Weare using the textbook Data Structure and Algorithms using Java by William I need help with modifying my code on the left. We are using the textbook Data Structure and Algorithms using Java by William McCallister.

public class GenericStack { private T[ ] data; private int top; private int size; public GenericStack() { top = -1; size = 100; data (T[ ]) new Object[100]; } public GenericStack(int n) { top = -1; size n; data = (T[ ]) new Object[n]; } public boolean push(T newNode) { GenericNode node = (GenericNode) newNode; if(top == size-1) return false; // overflow error ** else { top = top +1; data[top] (T) node.deepCopy(); return true; // push operation successful } } public T pop() { int topLocation; if(top == -1) return null; // ** underflow error ** else { topLocation top; top top -1; return data[topLocation); } } public void showAll() { for(int i top; i >= 0; i--) System.out.println(data[i].toString(); } } T[ ] data int size Generic Stack // Array of generic objects //default size of array is 3 1/top of the stack int top + + + + + GenericStack() GenericStack (int) boolean push (T) Tpop) void showAll() void reset() Tpeek() boolean isEmpty() boolean isFull) boolean expand) //Default constructor //Constructor that sets stack capacity 1/Add object to top of the stack 1/Remove and return object from top of stack // Console output of all objects in stack //Resets stack to empty 1/Return object from top of stack //Tests if stack is empty //Tests if stack is full 1/Expands size of stack when needed + + + + The default constructor should be modified so that it initializes the array size to 3. The reset method should reinitialize the stack to empty. The peek method should return the object at the top of the stack without removing it. The isEmpty method should test if the stack is empty (underflow condition) and return a boolean (true or false) value. The isFull method should test if the stack is full (overflow condition) and return a boolean value. The expand method is private to this class and you will modifiy the code so that it will only be called when needed. It should expand the stack every time a push operation is performed that would cause an overflow condition. Write another class named Test that contains a main method. Use this as a driver program to test the methods of the Generic Stack class. You need to use a class of objects to put in your stack structure for your tests. This may be the Listing from the text or your Student class for testing but you would have to make sure they implement the GenericNode interface from the text or you will get error messages. public class GenericStack { private T[ ] data; private int top; private int size; public GenericStack() { top = -1; size = 100; data (T[ ]) new Object[100]; } public GenericStack(int n) { top = -1; size n; data = (T[ ]) new Object[n]; } public boolean push(T newNode) { GenericNode node = (GenericNode) newNode; if(top == size-1) return false; // overflow error ** else { top = top +1; data[top] (T) node.deepCopy(); return true; // push operation successful } } public T pop() { int topLocation; if(top == -1) return null; // ** underflow error ** else { topLocation top; top top -1; return data[topLocation); } } public void showAll() { for(int i top; i >= 0; i--) System.out.println(data[i].toString(); } } T[ ] data int size Generic Stack // Array of generic objects //default size of array is 3 1/top of the stack int top + + + + + GenericStack() GenericStack (int) boolean push (T) Tpop) void showAll() void reset() Tpeek() boolean isEmpty() boolean isFull) boolean expand) //Default constructor //Constructor that sets stack capacity 1/Add object to top of the stack 1/Remove and return object from top of stack // Console output of all objects in stack //Resets stack to empty 1/Return object from top of stack //Tests if stack is empty //Tests if stack is full 1/Expands size of stack when needed + + + + The default constructor should be modified so that it initializes the array size to 3. The reset method should reinitialize the stack to empty. The peek method should return the object at the top of the stack without removing it. The isEmpty method should test if the stack is empty (underflow condition) and return a boolean (true or false) value. The isFull method should test if the stack is full (overflow condition) and return a boolean value. The expand method is private to this class and you will modifiy the code so that it will only be called when needed. It should expand the stack every time a push operation is performed that would cause an overflow condition. Write another class named Test that contains a main method. Use this as a driver program to test the methods of the Generic Stack class. You need to use a class of objects to put in your stack structure for your tests. This may be the Listing from the text or your Student class for testing but you would have to make sure they implement the GenericNode interface from the text or you will get error messages

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!