Question: Everything works except for display. Needs to be modified under LinkedStack.java. I also have but could not include StackADT.java, LinkTest.java and EmptyCollectionException.java. LinkedStack.java package jsjf;
Everything works except for display. Needs to be modified under LinkedStack.java. I also have but could not include StackADT.java, LinkTest.java and EmptyCollectionException.java.
LinkedStack.java
package jsjf;
import jsjf.exceptions.*;
public class LinkedStack
/** * Creates an empty stack. */ public LinkedStack() { count = 0; top = null; } public void push(T element) { LinearNode
temp.setNext(top); top = temp; count++; } public T pop() throws EmptyCollectionException { if (isEmpty()) //if the stack is empty, the message is printed out. { System.out.println("Stack is empty. Please push at least 1 element first."); } else {
T result = top.getElement(); top = top.getNext(); count--;
return result; } return null; } public T peek() throws EmptyCollectionException { if (isEmpty()) //if the stack is empty, the message is printed out. { System.out.println("Stack is empty. Please push at least 1 element first."); } else { return top.getElement(); } return null; } public boolean isEmpty() { return count==0; } public int size() { return count; } public String toString() { LinearNode
String s=""; for(int i=0;i public void display() { if (isEmpty()) //if the stack is empty, the message is printed out. { System.out.println("Nothing because the stack is empty. Please push at least 1 element first."); } else { for (int i =0; i LinearNode.java package jsjf; /** * Represents a node in a linked list. * * @author Java Foundations * @version 4.0 */ public class LinearNode /** * Creates an empty node. */ public LinearNode() { next = null; element = null; } /** * Creates a node storing the specified element. * @param elem element to be stored */ public LinearNode(T elem) { next = null; element = elem; } /** * Returns the node that follows this one. * @return reference to next node */ public LinearNode /** * Sets the node that follows this one. * @param node node to follow this one */ public void setNext(LinearNode /** * Returns the element stored in this node. * @return element stored at the node */ public T getElement() { return element; } /** * Sets the element stored in this node. * @param elem element to be stored at this node */ public void setElement(T elem) { element = elem; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
