数据结构----队列
作者:
pgydbh | 来源:发表于
2018-08-21 11:30 被阅读7次
结构
先进先出
需要size()----大小
需要push()----压入
需要pop()----弹出
采用链表不需要扩展
代码
public class Queue<T> {
private Node<T> head;
private Node<T> poi;
private int size;
public int size(){
return size;
}
public void push(T t){
if (head == null){
head = new Node<>();
poi = head;
} else {
poi = poi.next = new Node<>();
}
poi.t = t;
size++;
}
public T pop(){
if (size > 0){
T t = head.t;
head = head.next;
return t;
} else {
return null;
}
}
public static class Node<T>{
public T t;
public Node<T> next;
}
}
本文标题:数据结构----队列
本文链接:https://www.haomeiwen.com/subject/eomdiftx.html
网友评论