Package dsa

Class ResizingArrayQueue<Item>

  • All Implemented Interfaces:
    Queue<Item>, Iterable<Item>

    public class ResizingArrayQueue<Item>
    extends Object
    implements Queue<Item>
    This data type provides an implementation of the Queue API, using an array as the underlying data structure.
    • Constructor Detail

      • ResizingArrayQueue

        public ResizingArrayQueue()
        Constructs an empty queue.
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Queue
        Returns true if this queue is empty, and false otherwise.
        Specified by:
        isEmpty in interface Queue<Item>
        Returns:
        true if this queue is empty, and false otherwise.
      • size

        public int size()
        Description copied from interface: Queue
        Returns the number of items in this queue.
        Specified by:
        size in interface Queue<Item>
        Returns:
        number of items in this queue.
      • enqueue

        public void enqueue​(Item item)
        Description copied from interface: Queue
        Adds item to the end of this queue.
        Specified by:
        enqueue in interface Queue<Item>
        Parameters:
        item - the item.
      • peek

        public Item peek()
        Description copied from interface: Queue
        Returns the item at the front of this queue.
        Specified by:
        peek in interface Queue<Item>
        Returns:
        item at the front of this queue.
      • dequeue

        public Item dequeue()
        Description copied from interface: Queue
        Removes and returns the item at the front of this queue.
        Specified by:
        dequeue in interface Queue<Item>
        Returns:
        item at the front of this queue.
      • iterator

        public Iterator<Item> iterator()
        Returns an iterator to iterate over the items in this queue in FIFO order.
        Specified by:
        iterator in interface Iterable<Item>
        Returns:
        an iterator to iterate over the items in this queue in FIFO order.
      • toString

        public String toString()
        Returns a string representation of this queue.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this queue.
      • main

        public static void main​(String[] args)
        Unit tests the data type.
        Parameters:
        args - the command-line arguments.