Java單鏈表基本操作(六)--刪除重複節點;
阿新 • • 發佈:2019-01-29
package listnode;
public class DeleteDuplecate_SingleList {
public static void main(String[] args) {
Node head=ListNode.getSingleList();
ListNode.printList(head);
deleteNode(head);
ListNode.printList(head);
}
public static void deleteNode(Node head){
while (head.next!=null){
Node p=head;
while(p.next!=null){
if(p.next.data==head.data){
p.next=p.next.next;
}
p=p.next;
}
head=head.next;
}
}
}