-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_1.c
71 lines (66 loc) · 1.1 KB
/
2_1.c
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
#include<stdio.h>
struct node{
int data;
struct node *next;
}*head=NULL,*temp;
void main()
{
int n;
scanf("%d",&n);
create_nodes(n);
remove_duplicates();
print_nodes();
}
void create_nodes(int n)
{
int i;
for(i=0;i<n;i++)
{
struct node *new=(struct node*)malloc(sizeof(struct node));
new->next=NULL;
scanf("%d",&new->data);
if(head==NULL)
{
head=new;
temp=head;
}
else
{
temp->next=new;
temp=temp->next;
}
}
}
void print_nodes()
{
struct node *temp=head;
while(temp)
{
printf("%d-->",temp->data);
temp=temp->next;
}
printf("Null");
}
void remove_duplicates()
{
struct node*p,*s;
s=head;
while(s)
{
p=s;
while(p->next)
{
if(s->data==p->next->data)
{
temp=p->next;
p->next=p->next->next;
free(temp);
}
else
{
p=p->next;
}
}
s=s->next;
}
}