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 implements StackADT { private int count; private LinearNode top;

/** * Creates an empty stack. */ public LinkedStack() { count = 0; top = null; } public void push(T element) { LinearNode temp = new LinearNode(element);

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 runner=top;

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 { private LinearNode next; private T element;

/** * 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 getNext() { return next; }

/** * Sets the node that follows this one. * @param node node to follow this one */ public void setNext(LinearNode node) { next = node; }

/** * 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

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!