-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwork.h
123 lines (112 loc) · 2.05 KB
/
work.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
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
#ifndef WORK_H
#define WORK_H
#include<string.h>
//declaration header
struct employee
{
int id;
int index;
float salary;
char empname[30];
struct employee *next;
};
extern int c;
extern struct employee * head;
void sort(int a1);
void create()
{ ++c;
struct employee *a=(struct employee*)malloc(sizeof(struct employee));
struct employee *tmp=(struct employee*)malloc(sizeof(struct employee));
char empname[30];int ld;float salary;
printf("\nID:");
scanf("%d",&ld);
printf("\nEmployee Salary:");
scanf("%f",&salary);
printf("\nEmployee name:");
scanf("%s",empname);
if(head==NULL)
{
head=(struct employee*)malloc(sizeof(struct employee));
head->id=ld;
head->salary=salary;
strcpy(head->empname,empname);
head->index=c;
head->next=NULL;
}
else
{tmp=head;
a->id=ld;
a->salary=salary;
strcpy(a->empname,empname);
a->index=c;
a->next=NULL;
while(tmp->next!=NULL)
{tmp=tmp->next;
}
tmp->next=a;
}
printf("\nDetails created");
sort();
}
void sort(int a1)
{int c,up=1,choice;
struct employee *a=(struct employee*)malloc(sizeof(struct employee));
struct employee *b=(struct employee*)malloc(sizeof(struct employee));
b=head;
if(a1!=1){
printf("Enter the sort field:\n1.Name\n2.Id\n Your choice:");
scanf("%d",&choice);
switch(choice)
{case 1:b=head;
while(b!=NULL)
{ a=b->next;
(a!=NULL)
{
if(strcmp(b->empname,a->empname)>0)
{c=b->id;
b->id=a->id;
a->id=c;
}
a=a->next;
}
b->index=up++;
b=b->next;
}
break;
case 2:b=head;
while(b!=NULL)
{ a=b->next;
while(a!=NULL)
{
if((b->id)>(a->id))
{c=b->id;
b->id=a->id;
a->id=c;
}
a=a->next;
}
b->index=up++;
b=b->next;
}
break;
}
}
else
{b=head;
while(b!=NULL)
{ a=b->next;
while(a!=NULL)
{
if((b->id)>(a->id))
{c=b->id;
b->id=a->id;
a->id=c;
}
a=a->next;
}
b->index=up++;
b=b->next;
}
}
}
#endif