Class ImmutableStackImpl<T>

java.lang.Object
com.abstractkamen.datastructures.impl.stacks.ImmutableStackImpl<T>
Type Parameters:
T - type of element
All Implemented Interfaces:
ImmutableStack<T>, Iterable<T>

public class ImmutableStackImpl<T> extends Object implements ImmutableStack<T>
This class is the non-empty implementation.
  • Constructor Details

    • ImmutableStackImpl

      public ImmutableStackImpl()
  • Method Details

    • push

      public ImmutableStack<T> push(T element)
      Description copied from interface: ImmutableStack
      Creates a new stack out of the element and appends the previous stack to it.
      Specified by:
      push in interface ImmutableStack<T>
      Parameters:
      element - to create a new stack from
      Returns:
      new stack
    • pop

      public ImmutableStack<T> pop()
      Description copied from interface: ImmutableStack
      Returns the tail of the current stack.
      Specified by:
      pop in interface ImmutableStack<T>
      Returns:
      tail of current stack stack
    • peek

      public T peek()
      Description copied from interface: ImmutableStack
      See the current element.
      Specified by:
      peek in interface ImmutableStack<T>
      Returns:
      current element
    • depth

      public int depth()
      Description copied from interface: ImmutableStack
      The depth of current stack.
      Specified by:
      depth in interface ImmutableStack<T>
      Returns:
      depth of current stack
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: ImmutableStack
      True if stack is empty.
      Specified by:
      isEmpty in interface ImmutableStack<T>
      Returns:
      true if stack is empty
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>