-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path50.key map.c
84 lines (76 loc) · 1.26 KB
/
50.key map.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
72
73
74
75
76
77
78
79
80
81
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node
{
int key;
int data;
struct node* next;
};
struct node *head,*temp,*newnode;
void main()
{
int n,i,ch,val;
printf("Enter the no of nodes : ");
scanf("%d",&n);
head=0;
while(n>0)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("Enter the data : ");
scanf("%d",&newnode->data);
printf("\nEnter the key for the data %d : ",newnode->data);
scanf("%d",&newnode->key);
newnode->next=0;
if(head==0)
{
head=temp=newnode;
}
else
{
temp->next=newnode;
temp=newnode;
}
n--;
}
display();
do
{
printf("\nDo You want to search a element using key ???(0/1) ");
scanf("%d",&ch);
if(ch==1)
{
printf("\nEnter a key value : ");
scanf("%d",&val);
keysearch(val);
}
}while(ch==1);
}
void display()
{
int count=0;
temp=head;
printf("\n\nLinked List key value pairs are : \n\n");
while(temp!=0)
{
printf(" %d :",temp->key);
printf(" %d ---> ",temp->data);
temp=temp->next;
count++;
}
printf("NULL : NULL");
printf("\n\nNo of Nodes : %d",count);
}
void keysearch(int val)
{
temp=head;
while(temp!=0)
{
if(temp->key==val)
{
printf("\n\nThe data in the key %d is %d",val,temp->data);
break;
}
temp=temp->next;
}
}