-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLL3.cpp
67 lines (67 loc) · 1.08 KB
/
LL3.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
#include <stdio.h>
#include <stdlib.h>
struct node123
{
int data;
struct node123* link;
};
struct node123* head=NULL;
int k,m,f=0;
void create()
{
struct node123* p;
p=head;
struct node123* temp=(struct node123*)malloc(sizeof(struct node123));
scanf("%d",&temp->data);
temp->link=NULL;
if(head!=NULL)
{
while(p->link!=NULL)
p=p->link;
p->link=temp;
}
else
head=temp;
}
void insert()
{
struct node123* p=head;
while(p!=NULL)
{
if(p->data==k)
{
f=1;
break;
}
p=p->link;
}
if(f==0)printf("Node not found! \n");
else
{
struct node123* temp=(struct node123*)malloc(sizeof(struct node123));
temp->data=m;
temp->link=p->link;
p->link=temp;
}
}
void print(struct node123* temp)
{
printf("Linked List : ");
while(temp!=NULL)
{
printf("->%d",temp->data);
temp=temp->link;
}
}
int main() {
int n;
scanf("%d",&n);
while(n--)
create();
scanf("%d%d",&k,&m);
insert();
struct node123* temp;
temp=head;
print(temp);
return 0;
}