-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkunor.txt
More file actions
174 lines (167 loc) · 2.65 KB
/
linkunor.txt
File metadata and controls
174 lines (167 loc) · 2.65 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Linked List In An Unordered Manner.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<alloc.h>
void create();
void insert();
void delete();
void display();
typedef struct l_link{
int data;
struct l_link *link;
}*node;
node head,p,q,next;
int item,test;
main()
{
int ch;
char choice='y';
clrscr();
while(choice=='y')
{
// clrscr();
printf(" \n\n\n\t\t L I N K E D_L I S T O P E R A T I O N\n");
printf("\t\t\t (U N O R D E R E D M A N N E R) \n");
printf("\t\t\t 1.C R E A T I O N \n");
printf("\t\t\t 2.I N S E R T I O N \n");
printf("\t\t\t 3.D E L E T I O N\n");
printf("\t\t\t 4.E X I T\n");
printf("Enter Your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
create();
break;
case 2:
insert();
break;
case 3:
delete();
break;
case 4:
exit(0);
default:
printf("Invalid Choice\n Retry:");
break;
}
display();
printf("\nDo you Want To Continue[y/n]:");
scanf("%c",&choice);
choice=getchar();
}
getch();
}
void create()
{
int n,i;
item=1;
head=NULL;
printf("Enter The No. Of Data.");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter The data :");
scanf("%d",&item);
q=(node*)malloc(sizeof(node));
q->data=item;
q->link=NULL;
if(head==NULL)
head=q;
else
next->link=q;
next=q;
}
return;
}
void insert()
{
int key;
test=0;
printf("\n Enter The Data To Be Inserted:");
scanf("%d",&item);
printf("\nEnter The data To be Inserted Before.");
scanf("%d",&key);
q=(node*)malloc(sizeof(node));
q->data=item;
q->link=NULL;
if(head==NULL)
head=q;
if(key == head->data)
{
q->link=head;
head=q;
test=1;
}
else
{
p=head;
while(p->link!=NULL)
{
if(key == p->link->data)
{
test=1;
break;
}
p=p->link;
}
q->link=p->link;
p->link=q;
}
if(test==1)
printf("\n The Entered Data Is Inserted.");
else
printf("\n The Entered data To Be Inserted Before Is Not Found.\
\nThe Entered Data Is Inserted At The End");
return;
}
void delete()
{
test=0;
if(head==NULL)
return;
printf("\nEnter The Data To Be Deleted:");
scanf("%d",&item);
if(item == head->data)
{
head=head->link;
test=1;
}
p=head;
while(p!=NULL)
{
q=p->link;
if(item == q->data)
{
test=1;
break;
}
p=p->link;
}
p->link=q->link;
if(test==1)
printf("\n The Entered Item Is Deleted.");
else
printf("\n The Entered Item Is Not Found.");
free(q);
return;
}
void display()
{
p=head;
if(p==NULL)
{
printf("\n No Node Is Present.");
return;
}
printf("\nThe contents Of Linked List\n");
while(p!=NULL)
{
item = p->data;
printf("%d\t",item);
p=p->link;
}
return;
}