其他分享
首页 > 其他分享> > 7.2:链表删除给定值

7.2:链表删除给定值

作者:互联网

7.2:链表删除给定值

 

 1 public static Node removeValue(Node head, int num) {
 2         // head来到第一个不需要删的位置
 3         while (head != null) {
 4             if (head.value != num) {
 5                 break;
 6             }
 7             head = head.next;
 8         }
 9         // 1 ) head == null
10         // 2 ) head != null
11         Node pre = head;
12         Node cur = head;
13         while (cur != null) {
14             if (cur.value == num) {
15                 pre.next = cur.next;
16             } else {
17                 pre = cur;
18             }
19             cur = cur.next;
20         }
21         return head;
22     }

 

标签:Node,7.2,head,cur,pre,next,链表,给定,null
来源: https://www.cnblogs.com/yzmarcus/p/16229995.html