-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.h
80 lines (80 loc) · 1.43 KB
/
update.h
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
#include "work.h"
#include <string.h>
#ifndef UPDATE_H
#define UPDATE_H //UPDATE AND SEARCH FUNCTIONS
void update()
{int w,newindex;
float newsalary;
char newempname[30];
int found=0;
struct employee *a=(struct employee*)malloc(sizeof(struct employee));
printf("\nEnter the ID number:");
scanf("%d",&w);
printf("\nEnter the new Employee Salary:");
scanf("%f",&newsalary);
printf("\nEnter the new Employee name:");
scanf("%s",newempname);
int first=1,last=c,mid;
while(first<=last)
{a=head;
mid=(first+last)/2;
while(a!=NULL)
{if(a->index==mid)
{
if(a->id==w)
{printf("\nElement changed %d",a->index);
a->salary=newsalary;
strcpy(a->empname,newempname);
found=1;
break;
}
else if(w>(a->id))
{
first=mid+1;
break;
}
else
{
last=mid-1;break;
}
}
a=a->next;
}
if(found==1)
break;
}
}
void search()
{int w;
int found=0;
struct employee *a=(struct employee*)malloc(sizeof(struct employee));
printf("\nEnter the ID number:");
scanf("%d",&w);
int first=1,last=c,mid;
while(first<=last)
{a=head;
mid=(first+last)/2;
while(a!=NULL)
{if(a->index==mid)
{ if(a->id==w)
{printf("\nElement found at pos %d",a->index);
found=1;
break;
}
else if(w>(a->id))
{
first=mid+1;
break;
}
else
{
last=mid-1;break;
}
}
a=a->next;
}
if(found==1)
break;
}
}
#endif