package com.xdl.data_stru;
public class Day_Four_LinkQueueNode {
public E data;
public Day_Four_LinkQueueNode next;
}
package com.xdl.data_stru;
@SuppressWarnings("unused")
public class Day_Four_LinkQueue {
//队尾和队头对象化,data作为存储元素;
private Day_Four_LinkQueueNode front;
private Day_Four_LinkQueueNode rear;
private int len;
private void init() {
this.front =null;
this.rear =null;
}
private boolean push_stack(E e) {
Day_Four_LinkQueueNode p = new Day_Four_LinkQueueNode();
if (p==null) {
return false;
}else {
p.data =e;
p.next =null;
//如果队列为空,则赋予新的队头,反之则插入
if (!is_null()) {
this.front =p;
}else {
this.rear.next =p ;
}
//将插入的元素作为队尾
this.rear =p;
this.len++;
return true;
}
}
private boolean is_null() {
if (this.front ==null) {
return true;
}
return false;
}
//出队.应该先考虑释放当前的this.front ;取出的应该是 E e;
private E out_stack() {
Day_Four_LinkQueueNode p ;
E e;
if (!is_null()) {
e=this.front.data;
p=this.front;
//重置front,若只有一个元素的时候,则初始化
this.front =this.front.next;
if (this.front ==null) {
this.rear =null;
}
//释放原来的this.front;
p = null;
this.len--;
return e;
}
return null;
}
private E get_front() {
if (!this.is_null()) {
return this.front.data;
}
return null;
}
}