Merge pull request #10 from chinalwb/master
deleteByNode可以提前结束 && deleteByValue 增加可重复删除指定value的代码
This commit is contained in:
commit
61c8385b85
@ -87,6 +87,7 @@ public class SinglyLinkedList {
|
||||
|
||||
if (p == head) {
|
||||
head = head.next;
|
||||
return;
|
||||
}
|
||||
|
||||
Node q = head;
|
||||
@ -118,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() {
|
||||
|
Loading…
Reference in New Issue
Block a user