Package it.unimi.di.prog2.s10
Class BoundedIntQueue
java.lang.Object
it.unimi.di.prog2.s10.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 TypeMethodDescriptionint
dequeue()
Removes the element at the head of the queue.void
enqueue
(int x) Adds an element to the queue.boolean
int
hashCode()
boolean
isEmpty()
Determines whether the queue is empty, i.e., it does not contain any integer.boolean
isFull()
Determines whether the queue is full, i.e., it contains as many integers as its capacity.int
size()
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
- ifcapacity
is not positive.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Determines whether the queue is empty, i.e., it does not contain any integer.- Returns:
true
if the queue is empty,false
otherwise.
-
isFull
public boolean isFull()Determines whether the queue is full, i.e., it contains as many integers as its capacity.- Returns:
true
if the queue is full,false
otherwise.
-
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
public int hashCode() -
equals
-