-
Notifications
You must be signed in to change notification settings - Fork 1
/
linprob.c
73 lines (63 loc) · 1.19 KB
/
linprob.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
#include<stdio.h>
#include<stdlib.h>
#define SIZE 10
int a[SIZE],u[SIZE];
int loc;
void insert(int key,int* u){
loc=key%SIZE;
int i=loc;
while(u[i]==1 && i<SIZE){
i++;
}
if(i>=SIZE){
printf("UPDATE SIZE");
return;
}
u[i]=1;
a[i]=key;
}
void search(int key, int* u){
for(int i=0;i<SIZE;i++){
if (u[i]==1){
if(a[i]==key){
printf(" KEY FOUND ");
return;
}
}
}
printf(" KEY NOT FOUND ");
}
void display(int* u){
for(int i=0;i<SIZE;i++){
if(u[i]==1){
printf("a[%d]--->%d",i,a[i]);
printf("\n");
}
}
}
void main(){
for(int j=0;j<SIZE;j++){
u[j]=0;
}
int op,data;
printf("\tMENU\n");
while(1){
printf("\n1.Insert\n2.Traverse\n3.Search\n4.Exit\nSelect the operation:");
scanf("%d",&op);
switch (op) {
case 1: printf("Enter the data to be inserted:");
scanf("%d",&data);
insert(data,u);
break;
case 2: display(u);
break;
case 3: printf("Enter the item to be searched:");
scanf("%d",&data);
search(data,u);
break;
case 4: exit(0);
break;
default: printf("Invalid Selection!\n");
}
}
}