import java.util.*;
public class Main {
static Queue head,trail;
public void InitQueue() {
Queue queue=new Queue();
head=queue;
trail=queue;
}
public boolean isEmpty(Queue queue) {
if(queue.next==null)return true;
else return false;
}
public void EnQueue(int n) {
Queue q=new Queue(n);
trail.next=q;
trail=trail.next;
}
public void Dequeue(Queue queue) {
if(queue.next==null) {
System.out.println("该队列以空!!!");
} else {
if(queue.next==trail) {
System.out.println("队首元素" + queue.next.data + "以出队列。");
queue.next=null;
trail=queue;
}else {
System.out.println("队首元素" + queue.next.data + "以出队列。");
queue.next=queue.next.next;
}
}
}
public static void main(String[] args) {
Main queue=new Main();
queue.InitQueue();
queue.EnQueue(100);
System.out.println("尾"+trail.data);
queue.Dequeue(head);
System.out.println("尾"+trail.data);
for(int i=0;i<10;i++) {
queue.EnQueue( i+1);
}
queue.EnQueue(100);
System.out.println("尾"+trail.data);
queue.Dequeue(head);
System.out.println("头"+head.next.data);
}
}
class Queue{
int data;
Queue next;
public Queue() {
}
public Queue(int data) {
this.data=data;
}
}