Class StackOfDouble

java.lang.Object
edu.hws.jcm.data.StackOfDouble
All Implemented Interfaces:
Serializable

public class StackOfDouble extends Object implements Serializable
A standard stack of values of type double, which can grow to arbitrary size.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an initially empty stack.
    StackOfDouble(int initialSize)
    Create an empty stack that initially has space for initialSize items pre-allocated.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Return true if and only if the stack contains no items.
    void
    Clear all items from the stack.
    double
    pop()
    Remove and return the top item on the stack.
    void
    push(double x)
    Add x to top of stack.
    int
    Return the number of items on the stack.

    Methods inherited from class java.lang.Object

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

    • StackOfDouble

      public StackOfDouble()
      Create an initially empty stack. It initially has space allocated for one item.
    • StackOfDouble

      public StackOfDouble(int initialSize)
      Create an empty stack that initially has space for initialSize items pre-allocated. If initialSize <= 0, an initialSize of 1 is used.
  • Method Details

    • push

      public void push(double x)
      Add x to top of stack.
    • pop

      public double pop()
      Remove and return the top item on the stack. Will throw an exception of type java.util.EmptyStackException if the stack is empty when pop() is called.
    • isEmpty

      public boolean isEmpty()
      Return true if and only if the stack contains no items.
    • makeEmpty

      public void makeEmpty()
      Clear all items from the stack.
    • size

      public int size()
      Return the number of items on the stack.