Question
Inherit linked stack class is given below I need to use these to satisfy the requirements. All the information is provided above. I do not
Inherit linked stack class is given below I need to use these to satisfy the requirements. All the information is provided above. I do not have anymore information provided to further provide.
public LinkedStack() { top = null; }
public void push(T element) // Places element at the top of this stack. { LLNode newNode = new LLNode(element); newNode.setLink(top); top = newNode; }
public void pop() // Throws StackUnderflowException if this stack is empty, // otherwise removes top element from this stack. { if (isEmpty()) throw new StackUnderflowException("Pop attempted on an empty stack."); else top = top.getLink(); }
public T top() // Throws StackUnderflowException if this stack is empty, // otherwise returns top element of this stack. { if (isEmpty()) throw new StackUnderflowException("Top attempted on an empty stack."); else return top.getInfo(); }
public boolean isEmpty() // Returns true if this stack is empty, otherwise returns false. { return (top == null); }
public boolean isFull() // Returns false - a linked stack is never full { return false; }
}
Complete and submit LinkedStack2.java with following: 1. Inherit LinkedStack.java 2. Implement StackInterface2.java and complete following methods. 3. Add String toString() method as specified in page 153, problem 28(a) 4. Add int size() methodd as specified in page 153, problem 28(b) 5. Add void popSome(int count) method as specified in page 153, problem 28(c) 6. Add swapStart() method as specified in page 153, problem 28(d) 7. Add T poptop() method as specified in page 153, problem 28(e) 28. Add the following methods to the ArrayBoundedStack class, and create a test driver for each to show that they work correctly. In order to practice your array related coding skills, code each of these methods by accessing the internal variables of the ArrayBoundedstack, not by calling the previously defined public methods of the class. a. String tostring() creates and returns a string that correctly represents the current stack. Such a method could prove useful for testing and debugging the class and for testing and debugging applications that use the class. Assume each stacked element already provided its own reasonable tostring method. b. int size()-returns a count of how many items are currently on the stack. Do not add any instance variables to the ArrayBoundedstack class in order to implement this method. C. void popsome (int count) -removes the top count elements from the stack; throws StackUnderflowException if there are less than count elements on the stack. d. boolean swapstart()if there are less than two elements on the stack returns false; otherwise it reverses the order of the top two elements on the stack and returns true. e. T poptop()the "classic" pop operation, if the stack is empty it throws StackUnderflowException; otherwise it both removes and returns the top element of the stackStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started