Package project2

Class LinkedStack<T>

java.lang.Object
project2.LinkedStack<T>
Type Parameters:
T - the type of the elements in the stack
All Implemented Interfaces:
StackInterface<T>

public final class LinkedStack<T> extends Object implements StackInterface<T>
A class of stacks whose entries are stored in a chain of nodes. Implements the StackInterface.
Version:
1.0
Author:
Lea Wiranatha
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty stack.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all entries from this stack.
    boolean
    Detects whether this stack is empty.
    Retrieves this stack's top entry.
    pop()
    Removes and returns this stack's top entry.
    void
    push(T newEntry)
    Adds a new entry to the top of this stack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LinkedStack

      public LinkedStack()
      Creates an empty stack.
  • Method Details

    • push

      public void push(T newEntry)
      Adds a new entry to the top of this stack.
      Specified by:
      push in interface StackInterface<T>
      Parameters:
      newEntry - An object to be added to the stack.
      Throws:
      EmptyStackException - if the stack is empty
    • pop

      public T pop()
      Removes and returns this stack's top entry.
      Specified by:
      pop in interface StackInterface<T>
      Returns:
      The object at the top of the stack.
      Throws:
      EmptyStackException - if the stack is empty
    • peek

      public T peek()
      Retrieves this stack's top entry.
      Specified by:
      peek in interface StackInterface<T>
      Returns:
      The object at the top of the stack.
      Throws:
      EmptyStackException - if the stack is empty
    • isEmpty

      public boolean isEmpty()
      Detects whether this stack is empty.
      Specified by:
      isEmpty in interface StackInterface<T>
      Returns:
      True if the stack is empty.
    • clear

      public void clear()
      Removes all entries from this stack.
      Specified by:
      clear in interface StackInterface<T>