Question: In the LinkedNumberStack class, you are required to implement the following methods: push(int v) This method adds an integer to the top of the stack.

In the LinkedNumberStack class, you are required to implement the following methods: push(int v) This method adds an integer to the top of the stack. pop() This method removes an element from the top of the stack and returns the element. It throws a RuntimeException "pop attempted on an empty stack" if this operation is attempted on an empty stack. size() This method returns the number of elements on the stack. Note that you are only supposed to touch the above three methods. You are NOT allowed to create any other methods, instance variables, or make any changes to methods other than these three methods or files other than "LinkedNumberStack.java". Points will be taken off if you fail to follow this rule.

public class LinkedNumberStack implements NumberStack { // instance variable private LNode m_top; // check whether the stack is empty public boolean isEmpty() { if (m_top == null) return true; else return false; } // check whether the stack is full public boolean isFull() { return false; } // return the element at the top of the stack public int top() { if (isEmpty()) throw new RuntimeException("top attempted on an empty stack"); else return m_top.getInfo(); } // push a value onto the stack public void push(int v) { // TODO: implement this method
} // remove and return the value at the top of the stack public int pop() { TODO 
} return -1; 
 // return the number of elements on the stack public int size() { // TODO: implement this method return -1; // replace this statement with your own return } // return a string representation of the stack @Override public String toString() { String stackContent = ""; LNode current = m_top; while (current != null) { stackContent += current.getInfo() + " "; current = current.getLink(); } return stackContent; } }

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!