StacksQueues/Java/LinkedQueue
From charlesreid1
Link: https://charlesreid1.com:3000/cs/java/src/master/stacks-queues-deques/queues/LinkedQueue.java
LinkedQueue is a linked list based queue class implemented in Java.
Interface
This class implements the standard queue methods:
- add/enqueue
- remove/dequeue
as well as the convenience methods:
- size
- isEmpty
- rotate (rotate moves one element from front of queue to rear of queue)
Test
Here is a test of the LinkedQueue object that shows how it works; this manipulates a queue of integers.
public static void main(String[] args) {
LinkedQueue<Integer> q = new LinkedQueue<Integer>();
System.out.println(q);
q.enqueue(100);
q.enqueue(100);
q.enqueue(100);
System.out.println(q);
for(int i=0; i<10; i++) {
q.enqueue(i);
}
System.out.println(q);
q.dequeue();
q.dequeue();
q.dequeue();
System.out.println(q);
for(int i=0; i<3; i++) {
q.dequeue();
}
System.out.println(q);
System.out.println("Rotate:");
q.rotate();
System.out.println(q);
q.rotate();
System.out.println(q);
q.rotate();
System.out.println(q);
System.out.println("Size = " + q.size());
}