de.enough.polish.util
Class IntStack

java.lang.Object
  extended by de.enough.polish.util.IntList
      extended by de.enough.polish.util.IntStack
All Implemented Interfaces:
Externalizable, Serializable

public class IntStack
extends IntList

Provides a lifo stack for primitive int types

Copyright Enough Software 2007 - 2010

Author:
Robert Virkus, j2mepolish@enough.de

Constructor Summary
IntStack()
          Creates a new stack with the initial capacity of 10 and a growth factor of 75%
IntStack(int initialCapacity)
          Creates a new stack with the given initial capacity and a growth factor of 75%
IntStack(int initialCapacity, int growthFactor)
          Creates a new stack
 
Method Summary
 boolean empty()
          Determines whether this stack is empty
 int peek()
          Returns the element that has been added last without removing it.
 int pop()
          Returns the element that has been added last and removes it at the same time.
 void push(int element)
          Pushes an element on the stack.
 int search(int element)
          Returns the 1-based position where an object is on this stack.
 
Methods inherited from class de.enough.polish.util.IntList
add, add, clear, contains, get, getInternalArray, indexOf, read, removeElement, removeElementAt, set, size, toArray, toString, trimToSize, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntStack

public IntStack()
Creates a new stack with the initial capacity of 10 and a growth factor of 75%


IntStack

public IntStack(int initialCapacity)
Creates a new stack with the given initial capacity and a growth factor of 75%

Parameters:
initialCapacity - the capacity of this stack.

IntStack

public IntStack(int initialCapacity,
                int growthFactor)
Creates a new stack

Parameters:
initialCapacity - the capacity of this stack.
growthFactor - the factor in % for increasing the capacity when there's not enough room in this list anymore
Method Detail

push

public void push(int element)
Pushes an element on the stack.

Parameters:
element - the element

peek

public int peek()
Returns the element that has been added last without removing it.

Returns:
the last element

pop

public int pop()
Returns the element that has been added last and removes it at the same time.

Returns:
the last element

empty

public boolean empty()
Determines whether this stack is empty

Returns:
true when it is empty

search

public int search(int element)
Returns the 1-based position where an object is on this stack. If the element occurs as an item in this stack, this method returns the distance from the top of the stack of the occurrence nearest the top of the stack; the topmost item on the stack is considered to be at distance 1.

Parameters:
element - the element which might be on this stack
Returns:
the 1-based position or -1 if the element is not found.