public class MyList<T> {
private Node head;
private Node tail;
private int size;
public MyList(){
this(null,null);
}
public int size(){return size;}
public boolean add(T data){
if(this.head ==null&&this.tail==null){
Node node = new Node();
node.data = data;
node.prev = head;
node.next = null;
tail = head = node;
}else{
Node temp = head;
while(temp.next != null){
temp = temp.next;
}
Node node = new Node();
node.data = data;
node.prev = temp;
node.next = null;
temp.next = tail = node;
}
size++;
return true;
}
public boolean hasNext(Node node){
if(node!=null){
return true;
}
return false;
}
public MyList(Node head, Node tail) {
this.head = head;
this.tail = tail;
}
private static class Node<T>{
// 数据项
private T data;
// 前置节点
private Node prev;
// 后置节点
private Node next;
public Node() {
}
public Node(T data, Node prev, Node next) {
this.data = data;
this.prev = prev;
this.next = next;
}
}
}
自定义List
最新推荐文章于 2023-07-18 12:55:13 发布