Class Stack

  • All Implemented Interfaces:
    IStack

    public class Stack
    extends java.lang.Object
    implements IStack
    This class represents a stack data structure that can store characters.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MAX
      The macro definition similar to the C header files.
    • Constructor Summary

      Constructors 
      Constructor Description
      Stack()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void displayStack()
      Pretty prints the stack's elements, starting from the top-most element to the bottom.
      void insertBottom​(char elem)
      Inserts the specified element to the bottom of the stack.
      boolean isEmpty()
      Checks if the stack is empty.
      boolean isFull()
      Checks if the stack is full.
      int length()
      Returns the length of the stack.
      void makeNull()
      Clears the stack.
      void pop()
      Removes the element at the top of the stack if the stack is not empty.
      void push​(char elem)
      Pushes a character element onto the top of the stack if there is space.
      char top()
      Returns the element at the top of the stack, otherwise '\0' if the stack is empty.
      • Methods inherited from class java.lang.Object

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

      • MAX

        public static final int MAX
        The macro definition similar to the C header files.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Stack

        public Stack()
    • Method Detail

      • length

        public int length()
        Description copied from interface: IStack
        Returns the length of the stack.
        Specified by:
        length in interface IStack
        Returns:
        int
      • push

        public void push​(char elem)
        Description copied from interface: IStack
        Pushes a character element onto the top of the stack if there is space.
        Specified by:
        push in interface IStack
        Parameters:
        elem - The character element to push onto the stack.
      • pop

        public void pop()
        Description copied from interface: IStack
        Removes the element at the top of the stack if the stack is not empty.
        Specified by:
        pop in interface IStack
      • top

        public char top()
        Description copied from interface: IStack
        Returns the element at the top of the stack, otherwise '\0' if the stack is empty.
        Specified by:
        top in interface IStack
        Returns:
        char
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: IStack
        Checks if the stack is empty.
        Specified by:
        isEmpty in interface IStack
        Returns:
        true if the stack is empty, false otherwise.
      • isFull

        public boolean isFull()
        Description copied from interface: IStack
        Checks if the stack is full.
        Specified by:
        isFull in interface IStack
        Returns:
        true if the stack is full, false otherwise.
      • displayStack

        public void displayStack()
        Description copied from interface: IStack
        Pretty prints the stack's elements, starting from the top-most element to the bottom.
        Specified by:
        displayStack in interface IStack
      • makeNull

        public void makeNull()
        Description copied from interface: IStack
        Clears the stack.
        Specified by:
        makeNull in interface IStack
      • insertBottom

        public void insertBottom​(char elem)
        Description copied from interface: IStack
        Inserts the specified element to the bottom of the stack.
        Specified by:
        insertBottom in interface IStack
        Parameters:
        elem - the element to add to the stack