-
Notifications
You must be signed in to change notification settings - Fork 0
/
duplicates.cpp
65 lines (59 loc) · 1.25 KB
/
duplicates.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
using namespace std;
struct node {
int data;
node * next;
node(int data){
this->data=data;
this->next = NULL;
}
};
class lists{
node * start;
public:
lists(){
start = NULL;
}
void insertion(int item){
if(start == NULL){
start = new node(item);
return;
}
node * n1= new node(item);
n1->next = start;
start = n1;
}
void checkduplicates(){
node * ptr = start;
while(ptr != NULL){
node* ptr1 = ptr;
while(ptr1->next != NULL){
if(ptr->data == ptr1->next->data)
ptr1->next=ptr1->next->next;
else
ptr1=ptr1->next;
}
ptr=ptr->next;
}
}
void display(){
node * ptr =start;
while(ptr!=NULL){
cout<<ptr->data<<"\t";
ptr=ptr->next;
}
return;
}
};
int main(){
lists l1;
l1.insertion(9);
l1.insertion(7);
l1.insertion(9);
l1.insertion(7);
l1.insertion(5);
l1.display();
l1.checkduplicates();
l1.display();
return 0;
}