-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdouble.c
More file actions
115 lines (108 loc) · 1.81 KB
/
double.c
File metadata and controls
115 lines (108 loc) · 1.81 KB
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
115
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data ;
struct node *next;
struct node *pre;
};
struct node *head=NULL;
void add()
{
struct node *temp,*new;
int da,c=1;
printf("how many node you want to insert---- ");
scanf("%d",&c);
while(c--)
{
if (head==NULL)
{ head=(struct node*)malloc(sizeof(struct node));
printf("penter the data\n---");
scanf("%d",&da);
head->data=da;
head->next=NULL;
head->pre=NULL;
temp=head;
}
else
{ struct node *temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
new=(struct node*)malloc(sizeof(struct node));
printf("penter the data\n---");
scanf("%d",&da);
new->data=da;
new->next=NULL;
new->pre=temp;
temp->next=new;
}
}
}
void display()
{
struct node *temp=head;
while(temp!=NULL)
{printf("data->%d\n",temp->data);
temp=temp->next;
}
}
void dup()
{
struct node *temp=head;
struct node *temp1=head;
struct node *temp2,*temp3;
while(temp!=NULL)
{
while(temp1!=NULL)
{
if (temp1->data==temp->data)
{temp2=temp1;
temp3=temp1;
temp1=temp1->pre;
temp2=temp2->next;
temp1->next=temp2;
temp2->pre=temp1;
free(temp3);
}
temp1=temp1->next;
}
temp=temp->next;
}
}
void revd()
{
struct node *temp=head;
struct node *rev;
while(temp!=NULL)
{
if (temp->next==NULL){rev=temp;}
temp=temp->next;
}
while(rev!=NULL)
{
printf("data->%d\n",rev->data);
rev=rev->pre;
}
}
int main()
{
int choice=1;
while (choice==1)
{
int op;
printf("enter the choice \n 1 for adding node\n 2 for display\n 3 for remvoing duplicate \n----");
scanf("%d",&op);
if (op==1)
{
add();
}
else if (op==2){
display();
}
else{dup();}
printf("to go to menu press 1 ");
scanf("%d",&choice);
}
}