Nathan Sprague
public interface Queue<E> {
void enqueue(E item);
E dequeue();
E peek();
boolean isEmpty();
int size();
}
// Option A
index++;
if (index == array.length) {
index = 0;
}
// Option B
if (index == array.length - 1) {
index = 0;
} else {
index++;
}
// Option C
index = (index + 1) % array.length;
Big-
operation | cost |
---|---|
enqueue() |
|
dequeue() |
|
frontValue() |
|
length() |
* Amortized
Big-
operation | cost |
---|---|
enqueue() |
|
dequeue() |
|
frontValue() |
|
length() |
Space, Right Arrow or swipe left to move to next slide, click help below for more details