edu.cornell.cs.cs2110
Class Stack<T>

java.lang.Object
  extended by edu.cornell.cs.cs2110.AbstractBag<T>
      extended by edu.cornell.cs.cs2110.Stack<T>
Type Parameters:
T - the type of elements contained in this Stack.
All Implemented Interfaces:
Bag<T>, Iterable<T>

public class Stack<T>
extends AbstractBag<T>

A LIFO implementation of the Bag interface.


Constructor Summary
Stack()
           
 
Method Summary
 void clear()
          Removes all elements from the data structure.
 T extract()
          Extracts an element from the data structure.
 void insert(T item)
          Inserts an element into the data structure.
 int size()
          Returns the number of elements contained in the data structure.
 
Methods inherited from class edu.cornell.cs.cs2110.AbstractBag
isEmpty, iterator
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stack

public Stack()
Method Detail

extract

public T extract()
          throws NoSuchElementException
Extracts an element from the data structure. The element is deleted.

Specified by:
extract in interface Bag<T>
Specified by:
extract in class AbstractBag<T>
Returns:
the element extracted
Throws:
NoSuchElementException - if the data structure is empty

insert

public void insert(T item)
Inserts an element into the data structure.

Specified by:
insert in interface Bag<T>
Specified by:
insert in class AbstractBag<T>
Parameters:
item - the element to insert

clear

public void clear()
Removes all elements from the data structure.

Specified by:
clear in interface Bag<T>
Specified by:
clear in class AbstractBag<T>

size

public int size()
Returns the number of elements contained in the data structure.

Specified by:
size in interface Bag<T>
Specified by:
size in class AbstractBag<T>
Returns:
the number of elements