lab4打卡

由于pj1工程量有点大一时半会做不完,就先趁热打铁把双向链表的lab4做完了。。
PART1:

 1  public void insertFront(int i) {
 2      DListNode1 front1=new DListNode1(i);
 3      if(size==0) {
 4      head=front1;
 5      tail=head;    
 6      }
 7      else {
 8         front1.next=head;
 9         head.prev=front1;
10         head=front1;
11      }
12      size++;
13   }
View Code

PART2:

 1 public void removeFront() {
 2     if (size==0)
 3         return;
 4     else if(size==1){
 5         head=null;
 6         tail=null;        
 7         size--;
 8     }
 9     else {
10         head=head.next;
11         head.prev=null;
12         size--;
13     }
14   }
View Code

PART3:

1 public void insertFront(int i) {
2     DListNode2 front1=new DListNode2(i);
3     front1.next=head.next;
4     front1.prev=head;
5     head.next=front1;
6     head.next.next.prev=front1;
7     size++;
8   }
View Code

 PART4:

1   public void removeFront() {
2     head.next=head.next.next;
3     head.next.prev=head;
4     if(size!=0) {
5         size--;
6     }
7       
8   }
View Code

原文地址:https://www.cnblogs.com/jxtang/p/7224229.html