import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
DynamicQueue<Integer> queue = new DynamicQueue<>();
int[] key = {4,2,2,5,6,1,4,2,3};
for(int i=0; i<key.length; i++){
queue.enqueue(i);
}
int a;
for(int i=0; i<1_000_000_000; i++){
a = queue.dequeue();
queue.enqueue(a);
}
System.out.println("finish");
}
}
import java.io.IOException;
public class DynamicQueue<T> {
private Node<T> back;
private Node<T> front;
private int size;
public DynamicQueue() {
back = null;
size = 0;
}
public void enqueue(T e) {
if (isEmpty()){
Node<T> n = new Node<T>(null, null, e);
back = n;
front = n;
size++;
}
else {
Node<T> n = new Node<T>(null, front, e);
front.setNext(n);
size++;
front = n;
}
}
public T dequeue() throws IOException {
if (!isEmpty()){
T aux = (T) back.getElement();
size--;
back = back.getNext();
return aux;
}
else throw new NullPointerException();
}
public boolean isEmpty() {
return size == 0;
}
public int size() {
return size;
}
public boolean isFull() {
return false;
}
}
public class Node<T> {
private Node<T> next;
private Node<T> prev;
private T element;
public Node(Node<T> prox, Node<T> ant, T element) {
this.next = prox;
this.prev = ant;
this.element = element;
}
public Node<T> getNext() {
return next;
}
public void setNext(Node<T> prox) {
this.next = prox;
}
public Node<T> getPrev() {
return prev;
}
public void setPrev(Node<T> ant) {
this.prev = ant;
}
public T getElement() {
return element;
}
public void setElement(T element) {
this.element = element;
}
}