Class BoundedIntQueue
java.lang.Object
it.unimi.di.prog2.s12.BoundedIntQueue
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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBoundedIntQueue(int capacity) Creates a new bounded queue with the given capacity. -
Method Summary
Modifier and TypeMethodDescriptionintdequeue()Removes the element at the head of the queue.voidenqueue(int x) Adds an element to the queue.booleaninthashCode()booleanisEmpty()Determines whether the queue is empty, i.e., it does not contain any integer.booleanisFull()Determines whether the queue is full, i.e., it contains as many integers as its capacity.intsize()Returns the number of elements in the queue.toString()
-
Field Details
-
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- ifcapacityis not positive.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Determines whether the queue is empty, i.e., it does not contain any integer.- Returns:
trueif the queue is empty,falseotherwise.
-
isFull
public boolean isFull()Determines whether the queue is full, i.e., it contains as many integers as its capacity.- Returns:
trueif the queue is full,falseotherwise.
-
size
public int size()Returns the number of elements in the queue.- Returns:
- the number of elements.
-
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:
NoSuchElementException- if the queue is empty.
-
toString
-
hashCode
-
equals
-