Class ArrayBasedStack<T>


  • public final class ArrayBasedStack<T>
    extends java.lang.Object
    Array-based Stack.

    This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

    This class is not thread-safe.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private T[] array  
      (package private) static int DEFAULT_CAPACITY  
      private int size  
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayBasedStack()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isEmpty()  
      T pop()
      Removes and returns an element from the top of the stack (LIFO).
      void push​(T element)
      Add element to the top of the stack (LIFO).
      private void resizeArray​(int newCapacity)  
      int size()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • array

        private T[] array
      • size

        private int size
    • Constructor Detail

      • ArrayBasedStack

        public ArrayBasedStack()
    • Method Detail

      • push

        public void push​(T element)
        Add element to the top of the stack (LIFO).
        Parameters:
        element - The element to add
        Throws:
        java.lang.NullPointerException - if element is null
      • pop

        @Nullable
        public T pop()
        Removes and returns an element from the top of the stack (LIFO).
        Returns:
        the top most element in the stack (last one added)
      • isEmpty

        public boolean isEmpty()
      • size

        public int size()
      • resizeArray

        private void resizeArray​(int newCapacity)