-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASSG5_B220937CS_KAJA_PRACTICE.c
201 lines (184 loc) · 4.25 KB
/
ASSG5_B220937CS_KAJA_PRACTICE.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include<stdio.h>
#include<stdlib.h>
struct node{
int PID;
int BN;
struct node* next;
};
void ADD_patient(struct node **head,int pid,int bn){
struct node *new = (struct node*)malloc(sizeof(struct node));
new->PID = pid;
new->BN = bn;
new->next = NULL;
if((*head) == NULL){
(*head) = new;
}
else{
struct node *ptr = (*head);
if(ptr->BN > bn){
new->next = ptr;
(*head) = new;
}
else{
while((ptr->next)!=NULL && (ptr->next)->BN < bn){
ptr = ptr->next;
}
struct node *temp = ptr->next;
ptr->next = new;
new->next = temp;
}
}
}
void CALL_patient(struct node **head){
if((*head)==NULL){
printf("0\n");
}
else{
struct node* temp = (*head)->next;
printf("%d\n",(*head)->PID);
free((*head));
(*head) = temp;
}
}
void GET_patient_BN(struct node* head,int wanted){
if(head == NULL){
printf("0\n");
}
else{
while( head->next != NULL && head->PID != wanted ){
head = head->next;
}
if(head->PID == wanted){
printf("%d\n",head->BN);
}
else{
printf("0\n");
}
}
}
void GET_patient_PID(struct node* head,int wanted){
if(head == NULL){
printf("0\n");
}
else{
while( head->next != NULL && head->BN != wanted ){
head = head->next;
}
if(head->BN == wanted){
printf("%d\n",head->PID);
}
else{
printf("0\n");
}
}
}
void NEXT_patient(struct node* head){
if(head == NULL){
printf("0\n");
}
else{
printf("%d\n",head->PID);
}
}
void DOCTOR_a(struct node* head){
int count = 0;
if(head == NULL){
printf("0\n");
}
else{
while(head->next != NULL){
if(head->PID >=1 && head->PID <= 1000){
printf("%d ",head->PID);
count++;
}
head = head->next;
}
if(head->PID >=1 && head->PID <= 1000){
printf("%d",head->PID);
count++;
}
if(count != 0){
printf("\n");
}
if(count == 0){
printf("0\n");
}
}
}
void DOCTOR_b(struct node* head){
int count = 0;
if(head == NULL){
printf("0\n");
}
else{
while(head->next != NULL){
if(head->PID >=1001 && head->PID <= 10000){
printf("%d ",head->PID);
count++;
}
head = head->next;
}
if(head->PID >=1001 && head->PID <= 10000){
printf("%d",head->PID);
count++;
}
if(count != 0){
printf("\n");
}
if(count == 0){
printf("0\n");
}
}
}
void PRINT(struct node* head){
if(head == NULL){
printf("0\n");
}
else{
while((head->next) != NULL){
printf("%d %d\n",head->PID,head->BN);
head = head->next;
}
printf("%d %d\n",head->PID,head->BN);
}
}
int main()
{
char input[4];
struct node *list = NULL;
do{
scanf(" %s",input);
if (input[0] == 'a'){
int pid,bn;
scanf("%d",&pid);
scanf("%d",&bn);
ADD_patient(&list,pid,bn);
}
else if(input[0] == 'c'){
CALL_patient(&list);
}
else if(input[0] == 'n'){
NEXT_patient(list);
}
else if(input[0] =='b' && input[1] == 'n'){
int s_pid;
scanf("%d",&s_pid);
GET_patient_BN(list,s_pid);
}
else if(input[0] =='p' && input[1] == 'i' && input[2]== 'd'){
int s_bn;
scanf("%d",&s_bn);
GET_patient_PID(list,s_bn);
}
else if(input[0] == 'd' && input[1] == 'A'){
DOCTOR_a(list);
}
else if(input[0] == 'd' && input[1] == 'B'){
DOCTOR_b(list);
}
else if(input[0] == 'd' && input[1] == '\0'){
PRINT(list);
}
}while(input[0] != 'e');
return 1;
}