From 20e65972d13fb5390df3009cb9097affcaf39bfd Mon Sep 17 00:00:00 2001 From: Rain Liu Date: Sat, 6 Oct 2018 22:38:31 +0800 Subject: [PATCH 1/4] =?UTF-8?q?deleteByNode=20=E5=8F=AF=E4=BB=A5=E6=8F=90?= =?UTF-8?q?=E5=89=8D=E7=BB=93=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- java/06_linkedlist/SinglyLinkedList.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/06_linkedlist/SinglyLinkedList.java b/java/06_linkedlist/SinglyLinkedList.java index 3978c0b..bb92f50 100644 --- a/java/06_linkedlist/SinglyLinkedList.java +++ b/java/06_linkedlist/SinglyLinkedList.java @@ -87,6 +87,7 @@ public class SinglyLinkedList { if (p == head) { head = head.next; + return; } Node q = head; From 1d24c84df92d1b0bf2f5a37221d32c21e8fe1357 Mon Sep 17 00:00:00 2001 From: Rain Liu Date: Sat, 6 Oct 2018 23:06:09 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=AF=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=88=A0=E9=99=A4=E6=8C=87=E5=AE=9Avalue=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- java/06_linkedlist/SinglyLinkedList.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/java/06_linkedlist/SinglyLinkedList.java b/java/06_linkedlist/SinglyLinkedList.java index bb92f50..0931d13 100644 --- a/java/06_linkedlist/SinglyLinkedList.java +++ b/java/06_linkedlist/SinglyLinkedList.java @@ -119,6 +119,22 @@ public class SinglyLinkedList { } else { q.next = q.next.next; } + + // 可重复删除指定value的代码 + /* + if (head != null && head.data == value) { + head = head.next; + } + + Node pNode = head; + while (pNode != null) { + if (pNode.next.data == data) { + pNode.next = pNode.next.next; + continue; + } + pNode = pNode.next; + } + */ } public void printAll() { From 181f721ad6e0c24579ad6689c9f589009e28936a Mon Sep 17 00:00:00 2001 From: Rain Liu Date: Sat, 6 Oct 2018 23:09:22 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=9B=9E=E6=BB=9AdeleteByNode=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=8F=90=E5=89=8D=E7=BB=93=E6=9D=9F=E7=9A=84=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- java/06_linkedlist/SinglyLinkedList.java | 1 - 1 file changed, 1 deletion(-) diff --git a/java/06_linkedlist/SinglyLinkedList.java b/java/06_linkedlist/SinglyLinkedList.java index 0931d13..6820df9 100644 --- a/java/06_linkedlist/SinglyLinkedList.java +++ b/java/06_linkedlist/SinglyLinkedList.java @@ -87,7 +87,6 @@ public class SinglyLinkedList { if (p == head) { head = head.next; - return; } Node q = head; From 04c7c20b682cbcc2a79abbf32a76e4b1ce2e1159 Mon Sep 17 00:00:00 2001 From: Rain Liu Date: Sat, 6 Oct 2018 23:15:37 +0800 Subject: [PATCH 4/4] =?UTF-8?q?deleteByNode=E5=8F=AF=E4=BB=A5=E6=8F=90?= =?UTF-8?q?=E5=89=8D=E7=BB=93=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当删除节点为头结点的时候可以不用进行循环查找要删除节点的前驱节点 --- java/06_linkedlist/SinglyLinkedList.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/06_linkedlist/SinglyLinkedList.java b/java/06_linkedlist/SinglyLinkedList.java index 6820df9..0931d13 100644 --- a/java/06_linkedlist/SinglyLinkedList.java +++ b/java/06_linkedlist/SinglyLinkedList.java @@ -87,6 +87,7 @@ public class SinglyLinkedList { if (p == head) { head = head.next; + return; } Node q = head;