Skip to content

Commit

Permalink
Merge pull request wangzheng0822#10 from chinalwb/master
Browse files Browse the repository at this point in the history
deleteByNode可以提前结束 && deleteByValue 增加可重复删除指定value的代码
  • Loading branch information
wangzheng0822 authored Oct 8, 2018
2 parents d4e83b4 + 04c7c20 commit 61c8385
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions java/06_linkedlist/SinglyLinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void deleteByNode(Node p) {

if (p == head) {
head = head.next;
return;
}

Node q = head;
Expand Down Expand Up @@ -118,6 +119,22 @@ public void deleteByValue(int value) {
} 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() {
Expand Down

0 comments on commit 61c8385

Please sign in to comment.