-
Notifications
You must be signed in to change notification settings - Fork 4
/
deleteDuplicate.cpp
121 lines (93 loc) · 1.12 KB
/
deleteDuplicate.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* We will delete duplicate node in Sorted Linked List */
#include<iostream>
using namespace std;
struct node
{
int data;
node *next;
};
class List
{
node *h,*t;
public:
List() { h=NULL,t=NULL; }
float size=0;int mc=1;
node *m;
void add(int x)
{
node *n=new node;
if(h==NULL)
{ n->data=x;
h=n; t=n; m=n;
}
else
{
n->data=x;
t->next=n;
t=n;
}
size++;
}
void deleteDupli()
{
node *prv,*police;
prv=NULL; police=h;
while(police->next!=NULL)
{
if(police->data==(police->next)->data)
{
if(prv==NULL)
{
h=h->next;
police=police->next;
//prv=police;
}
else
{ police=police->next;
prv->next=police;
}
}
else
{ prv=police;
police=police->next;
}
}
}
void print()
{
node *tmp;
tmp=h;
while(tmp!=NULL)
{
cout<<tmp->data<<" ";
tmp=tmp->next;
}
}
};
int main()
{
List a;
a.add(2);
a.add(2);
a.add(2);
a.add(2);
a.add(5);
a.add(10);
a.add(10);
a.add(10);
a.add(10);
a.add(10);
a.add(10);
a.add(10);
a.add(11);
a.add(12);
a.add(19);
a.add(20);
a.add(20);
a.add(21);
a.add(21);
a.add(21);
a.add(21);
a.deleteDupli();
a.print();
}