-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreove duplicate node.cpp
70 lines (65 loc) · 1.03 KB
/
reove duplicate node.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
#include<bits/stdc++.h> //This program is to remove duplicate node from sorted linked list
using namespace std;
struct Node {
int data;
struct Node *next;
}*first,*last;
void create(int a[],int size)
{
struct Node *ptr,*last;
first=new Node;
first->data=a[0];
first->next=NULL;
last=first;
for(int i=1;i<size;i++)
{
ptr=new Node;
ptr->data=a[i];
ptr->next=NULL;
last->next=ptr;
last=ptr;
}
}
void display()
{
struct Node *ptr;
ptr=first;
cout<<endl;
while(ptr!=NULL)
{
cout<<ptr->data<<" ";
ptr=ptr->next;
}
}
void isdup()
{
struct Node *ptr,*d;
ptr=first;
d=first->next;
while(d!=NULL)
{
if(ptr->data != d->data)
{
ptr=d;
d=d->next;
}
else
{
ptr->next=d->next;
delete d;
d=ptr->next;
}
}
}
int main()
{
int a[]={3,3,4,4,4,4,5,8,8,8};
int n=sizeof(a)/sizeof(int);
create(a,n);
cout<<"Initial Linked List=\n";
display();
isdup();
cout<<"\nLinked List with No Duplication=\n";
display();
return 0;
}