weka.core.neighboursearch.covertrees

## 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:
    java.io.Serializable, RevisionHandler

      public class Stack<T>
      extends java.lang.Object
      implements java.io.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:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `java.util.ArrayList<T>` | `elements` The elements inside the stack.
    `int` | `length` The number of elements in the stack.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Stack()` Constructor.
    `Stack(int capacity)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addAll(java.util.Collection<? extends T> c)` Adds all the given elements in the stack.
    `void` | `clear()` Removes all the elements from the stack.
    `T` | `element(int i)` Returns the ith element in the stack.
    `java.lang.String` | `getRevision()` Returns the revision string.
    `T` | `last()` Returns the last element in the stack.
    `T` | `pop()` Pops (removes) the first (last added) element in the stack.
    `void` | `push(Stack<T> v, T new_ele)` Pushes the given element onto the given stack.
    `void` | `push(T new_ele)` Pushes the given element to the stack.
    `void` | `replaceAllBy(Stack<T> s)` 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.
    `java.util.List<T>` | `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 Detail

    - #### length

          public int length

      The number of elements in the stack.

    - #### elements

          public java.util.ArrayList<T> elements

      The elements inside the stack.

  - ### Constructor Detail

    - #### Stack

          public Stack()

      Constructor.

    - #### Stack

          public Stack(int capacity)

      Constructor.
      Parameters:
        `capacity` - The initial capacity of the stack.

  - ### Method Detail

    - #### 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 java.util.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(java.util.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 java.lang.String getRevision()

      Returns the revision string.
      Specified by:
        `getRevision` in interface `RevisionHandler`
      Returns:
        the revision