Stack

Description

This is a last in, first out data structure with two primary functions: push and pop.

Relationships

  • Node : Uses the Node data object to populate with.

Members

  • Node[] stack - the array of Node objects contained in this data structure
  • int endIndex - this value indicates the last known index where a data value is represented
  • int count - this indicates the number of data values that can be contained (eg the length of the data structure)

Methods

  • Stack(int length)
    • constructor instantiates the stack array using this length parameter
    • sets the count to the length parameter and sets the endIndex value to 0 (no values contained yet)
  • Push(Node value)
    • checks the equality between the endIndex and the count (meaning no more data slots available) - if this check is true it creates a new stack with the double the count for data slots and populates that array with the previous data items
    • sets the value parameter to the endIndex slot in the stack
  • Pop()
    • returns the NodeValue located at the endIndex
    • if the stack is empty, it returns -1
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License