Class Stack<T>

java.lang.Object
weka.core.neighboursearch.covertrees.Stack<T>
Type Parameters:
T - The type of elements to be stored in the stack.
All Implemented Interfaces:
Serializable, RevisionHandler

public class Stack<T> extends Object implements Serializable, RevisionHandler
Class implementing a stack.
Version:
$Revision: 10203 $
Author:
Alina Beygelzimer (original C++ code), Sham Kakade (original C++ code), John Langford (original C++ code), Ashraf M. Kibriya (amk14[at-the-rate]cs[dot]waikato[dot]ac[dot]nz) (Java port)
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The elements inside the stack.
    int
    The number of elements in the stack.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
    Stack(int capacity)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAll(Collection<? extends T> c)
    Adds all the given elements in the stack.
    void
    Removes all the elements from the stack.
    element(int i)
    Returns the ith element in the stack.
    Returns the revision string.
    Returns the last element in the stack.
    pop()
    Pops (removes) the first (last added) element in the stack.
    void
    push(T new_ele)
    Pushes the given element to the stack.
    void
    push(Stack<T> v, T new_ele)
    Pushes the given element onto the given stack.
    void
    Replace all elements in the stack with the elements of another given stack.
    void
    set(int i, T e)
    Sets the ith element in the stack.
    subList(int beginIdx, int uptoLength)
    Returns a sublist of the elements in the stack.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • length

      public int length
      The number of elements in the stack.
    • elements

      public ArrayList<T> elements
      The elements inside the stack.
  • Constructor Details

    • Stack

      public Stack()
      Constructor.
    • Stack

      public Stack(int capacity)
      Constructor.
      Parameters:
      capacity - The initial capacity of the stack.
  • Method Details

    • last

      public T last()
      Returns the last element in the stack.
      Returns:
      The last element.
    • element

      public T element(int i)
      Returns the ith element in the stack.
      Parameters:
      i - The index of the element to return.
      Returns:
      The ith element.
    • set

      public void set(int i, T e)
      Sets the ith element in the stack.
      Parameters:
      i - The index at which the element is to be inserted.
      e - The element to insert.
    • subList

      public List<T> subList(int beginIdx, int uptoLength)
      Returns a sublist of the elements in the stack.
      Parameters:
      beginIdx - The start index of the sublist.
      uptoLength - The length of the sublist.
      Returns:
      The sublist starting from beginIdx and of length uptoLength.
    • clear

      public void clear()
      Removes all the elements from the stack.
    • addAll

      public void addAll(Collection<? extends T> c)
      Adds all the given elements in the stack.
      Parameters:
      c - The collection of elements to add in the stack.
    • replaceAllBy

      public void replaceAllBy(Stack<T> s)
      Replace all elements in the stack with the elements of another given stack. It first removes all the elements currently in the stack, and then adds all the elements of the provided stack.
      Parameters:
      s - The stack whose elements should be put in this stack.
    • pop

      public T pop()
      Pops (removes) the first (last added) element in the stack.
      Returns:
      The poped element.
    • push

      public void push(T new_ele)
      Pushes the given element to the stack.
      Parameters:
      new_ele - The element to be pushed to the stack.
    • push

      public void push(Stack<T> v, T new_ele)
      Pushes the given element onto the given stack.
      Parameters:
      v - The stack onto push the element.
      new_ele - The element to push.
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface RevisionHandler
      Returns:
      the revision