Queue

Description

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

Relationships

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

Members

  • Node[] queue - the array of Node objects contained in this data structure
  • int beginIndex - the first element in the array (this won't always be 0, with the way we call Pop()) - the element in this index is what is returned upon Pop()
  • int endIndex - this value indicates the last known index where the last data value that was entered is represented
  • int count - this indicates the number of data values that is contained
  • int length - this indicates the size of the array that represents the data structure (Node[] queue)

Methods

  • Queue(int length)
    • constructor instantiates the queue array using this length parameter
    • sets the length attribute to the parameter
    • sets the indices and count to 0 to begin with
  • Push(Node value)
    • checks to see if the count exceeds the length of the array - if so, then a new queue array needs to be created where the length of the array is doubled - the new queue is then populated from the beginIndex being 0 (afterward the indices, count, and length need to be modified to accommodate this change)
    • at the end, the Node needs to be added to the endIndex of the array
  • Pop()
    • returns the NodeValue located at the beginIndex and removes that value from the queue
    • the beginIndex is then incremented to indicate the new start of the queue
    • if the queue is empty (if count equates to 0), it returns -1
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License