-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveDuplicateLL.cpp
More file actions
48 lines (38 loc) · 824 Bytes
/
RemoveDuplicateLL.cpp
File metadata and controls
48 lines (38 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Remove all duplicate elements from a sorted linked list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* RemoveDuplicates(Node *head)
{
if(head==nullptr){
return nullptr;
}
if(head->next==nullptr){
return head;
}
Node *trav=new Node;
trav=head;
// if(trav->data == trav1->data){
// head->next=nullptr;
// delete trav1;
//return head;
//}
while(trav->next!=nullptr){
//
if(trav->data==trav->next->data){
Node *temp=new Node;
temp=trav->next;
trav->next=trav->next->next;
delete temp;
}
else{
trav=trav->next;
}
}
return head;
}