Package edu.hws.jcm.data
Class StackOfDouble
java.lang.Object
edu.hws.jcm.data.StackOfDouble
- All Implemented Interfaces:
Serializable
A standard stack of values of type double, which can grow to arbitrary size.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an initially empty stack.StackOfDouble(int initialSize) Create an empty stack that initially has space for initialSize items pre-allocated. -
Method Summary
Modifier and TypeMethodDescriptionbooleanisEmpty()Return true if and only if the stack contains no items.voidClear all items from the stack.doublepop()Remove and return the top item on the stack.voidpush(double x) Add x to top of stack.intsize()Return the number of items on the stack.
-
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 invalid input: '<'= 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.
-