Class BoundedIntQueue

java.lang.Object
it.unimi.di.prog2.e10.BoundedIntQueue

public class BoundedIntQueue extends Object
A queue is a mutable data structure that provides access to its elements in first-in/first-out order.

A bounded queue has an upper bound, established when a queue is created, on the number of elements that can be stored in the queue.

  • Constructor Details

    • BoundedIntQueue

      public BoundedIntQueue(int capacity)
      Creates a new bounded queue with the given capacity.
      Parameters:
      capacity - the capacity of the queue.
      Throws:
      IllegalArgumentException - if capacity is negative.
  • Method Details

    • enqueue

      public void enqueue(int x)
      Adds an element to the queue.
      Parameters:
      x - the element to add.
      Throws:
      IllegalStateException - if the queue is full.
    • dequeue

      public int dequeue()
      Removes the element at the head of the queue.
      Returns:
      the element at the head of the queue.
      Throws:
      IllegalStateException - if the queue is empty.