class ListNode{
public int val;
public ListNode prev;
public ListNode next;
public ListNode(int val){ //构造方法和类名是一样的,只对val初始化,因为当又一个节点的时候,不知道前一个后一个是谁
this.val = val;
}
}
public class MyDoubleList {
public ListNode head; //ListNode--是个类型 //head--指向头节点
public ListNode last; //last--指向尾巴节点
//一、打印双向链表
public void display(){
ListNode cur = this.head;
while (cur != null){
System.out.print(cur.val+" ");
cur = cur.next;
}
System.out.println( );
}
//二、得到双链表的长度
public int size(){
ListNode cur = this.head;
int count = 0;
while (cur != null){
count++;
cur = cur.next;
}
return count;
}
//三、查找双链表是否包含关键字key
public boolean contains(int key){
ListNode cur = this.head;
while (cur !&#