Merge pull request #10 from chinalwb/master

deleteByNode可以提前结束 && deleteByValue 增加可重复删除指定value的代码
This commit is contained in:
wangzheng0822 2018-10-08 11:09:38 +08:00 committed by GitHub
commit 61c8385b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,6 +87,7 @@ public class SinglyLinkedList {
if (p == head) { if (p == head) {
head = head.next; head = head.next;
return;
} }
Node q = head; Node q = head;
@ -118,6 +119,22 @@ public class SinglyLinkedList {
} else { } else {
q.next = q.next.next; 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() { public void printAll() {