//队列的链式存储结构
public class MyLinkQueue {
//链表结点
private class Node {
private int data;
private Node next;
public Node() {
this.data = 0;
this.next = null;
}
public Node(int data) {
this.data = data;
}
}
//队首
private Node front;
//队尾
private Node rear;
MyLinkQueue() {
front = new Node();
rear = front;
}
/*
* 描述:入队操作
* 参数:(结点数据)
* 返回值:
* */
public void in(int data) {
rear.next = new Node(data);
rear = rear.next;
}
/*
* 描述:出队操作
* 参数:
* 返回值:
* */
public void out() {
//检查链表是否为空
if(!isEmpty()) {
System.out.println("队列为空");
return;
}
if(front.next == rear) {
rear = front;
}
System.out.println(front.next.data);
front.next = front.next.next;
}
/*
* 描述:检查队列是否为空
* */
public boolean isEmpty() {
if(front == rear) {
return false;
}
return true;
}
}
特殊线性表队列的链式存储结构的java实现
最新推荐文章于 2022-09-18 13:45:57 发布