-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFP.cpp
More file actions
315 lines (255 loc) · 5.75 KB
/
Copy pathFP.cpp
File metadata and controls
315 lines (255 loc) · 5.75 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
struct node {
int nilai;
char nama [50];
int nomor;
int rank;
struct node *next;
};
typedef struct node node;
//Daftar Fungsi yang dibuat
void dequeue(node **head);
void enqueue(node **head, int total);
int traverse(node *head);
void input_nilai(node *head);
void mengurutkan(node **head);
void sisa (node **head, int total);
void numbering(node *head);
void show_all(node *head);
node* SortedMerge( node* a, node* b);
void MergeSort(node** head);
void rank (node *head);
void split( node* source , node** front,node** back);
//********************************************
//THE MAIN PROGRAM
int main()
{
node *head;
head = NULL;
node *sort =NULL;
char Menu1, Menu2, Menu3;
int total;
printf("PROGRAM SELEKSI PESERTA PELATIHAN \n\n");
printf("Masukkan total peserta yang dapat pendaftar: ");
scanf("%d", &total);
do{
system("cls");
printf("PROGRAM SELEKSI PESERTA PELATIHAN \n\n");
printf("Masukkan total peserta yang dapat pendaftar: %d", total);
printf("\n\n 1. Seleksi Pendaftaran");
printf("\n 2. Seleksi Nilai \n");
printf("ENTER YOUR OPTION (PRESS 'q' FOR QUIT) : ");
fflush(stdin); scanf("%c", &Menu1);
if(Menu1=='1') {
do{
system("cls");
printf("Selesksi Pendaftaran : \n\n");
printf("1. Masukkan nama peserta\n");
printf("2. Menampilkan nama peserta \n");
printf("3. Sisa Kuota\n");
printf("ENTER YOUR OPTION (PRESS 'q' FOR QUIT) : ");
fflush(stdin);
scanf("%c", &Menu2);
if(Menu2=='1')
enqueue(&head, total);
else if (Menu2=='2')
traverse(head);
else if (Menu2=='3')
sisa (&head,total);
} while (Menu2 != 'q');
}else if (Menu1=='2'){
do{
system("cls");
printf("Seleksi Nilai: \n\n");
printf("1. Memberi nomer peserta kepada setiap peserta \n");
printf("2. Menginput nilai tes ke semua peserta\n");
printf("3. Mengurutkan peserta berdasarkan nilai\n");
printf("4. Tampilkan data peserta\n");
printf("ENTER YOUR OPTION (PRESS 'q' FOR QUIT) : ");
fflush(stdin);
scanf("%c", &Menu3);
if(Menu3=='1')
numbering(head);
else if (Menu3=='2')
input_nilai(head);
else if (Menu3=='3')
MergeSort(&head);
else if (Menu3=='4')
show_all(head);
}while (Menu3 != 'q');
}else{
printf("Inputan Anda tidak ada dalam Menu");
}
}while (Menu1 != 'q');
}
void enqueue(node **head, int total){
char name[50];
node *pPre, *pNew, *pCur;
int batas;
system("cls");
batas =traverse(*head);
if (batas<=total){
printf("\n Masukkan nama peserta: "); fflush(stdin);
gets(name);
pNew = (node *)malloc(sizeof(node));
strcpy(pNew->nama, name);
pPre=*head;
if (pPre==NULL){
pNew->next = NULL;
*head=pNew;
}
else{
while (pPre->next != NULL) {
pPre = pPre -> next;
}
if (pPre->next != NULL){
printf("\nDATA NOT FOUND !");
getch();}
else if(pPre->next== NULL ) {
pNew->next= NULL;
pPre->next=pNew;
}
}
}else if (batas>=total){
printf("\n===Maaf Kuota sudah penuh=== ");
getch();
}
}
void sisa (node **head,int total){
int jum;
int sisa;
jum = traverse(*head);
sisa = total-jum;
printf("\nKuota yang tersisa: %d", sisa+1);
getch();
}
int traverse(node *head){
int i=1;
node *pWalker;
system("cls");
pWalker = head;
while (pWalker != NULL){
printf("%s->", pWalker -> nama);
pWalker = pWalker -> next;
i++;
}
printf("END");
getch();
return i;
}
void numbering(node *head){
node *pWalker;
int nomer, i=1;
nomer = 221200;
system("cls");
pWalker = head;
while (pWalker != NULL){
pWalker->nomor = nomer+i;
pWalker = pWalker -> next;
i++;
}
printf("Pemberian Nomer Peserta sudah selesai");
getch();
}
void input_nilai(node *head){
node *pWalker;
system("cls");
pWalker = head;
while (pWalker != NULL){
printf("\n Nama peserta: %s \n", pWalker->nama);
printf("Nomer peserta: %i \n", pWalker->nomor);
printf("Input nilai peserta: " );
scanf("%i",&pWalker->nilai);
pWalker = pWalker -> next;
}
printf("END");
}
node* SortedMerge( node* a, node* b)
{
node* result;
result = NULL;
if(a==NULL)
return(b);
else if(b==NULL)
return(a);
if(a->nilai >= b->nilai)
{
result = a;
result->next = SortedMerge(a->next,b);
}
else
{
result = b;
result->next = SortedMerge(a,b->next);
}
return(result);
}
void split( node* source , node** front,node** back)
{
node* slow;
node* fast;
if(source==NULL || source->next==NULL)
{
*front = source;
*back = NULL;
}
else
{
slow = source;
fast = source->next;
while(fast!=NULL)
{
fast = fast->next;
if(fast!=NULL)
{
fast = fast->next;
slow = slow->next;
}
}
*front = source;
*back = slow->next;
slow->next=NULL;
}
}
void MergeSort(node** head)
{
node* temphead = *head;
node* a;
node* b;
if((temphead==NULL) || (temphead->next==NULL))
return;
split(temphead,&a,&b);
MergeSort(&a);
MergeSort(&b);
*head = SortedMerge(a,b);
rank(*head);
}
void rank (node *head){
node *pWalker;
int n=traverse(head);
int i=1;
system("cls");
pWalker = head;
while (pWalker != NULL){
pWalker->rank=i;
i++;
pWalker=pWalker->next;
}
}
void show_all(node *head){
node *pWalker;
system("cls");
pWalker = head;
while (pWalker != NULL){
printf("\n Nama peserta: %s \n", pWalker->nama);
printf("Nomer peserta: %i \n", pWalker->nomor);
printf("Nilai peserta: %i \n", pWalker->nilai);
printf("Ranking: %i \n", pWalker->rank);
pWalker = pWalker -> next;
}
printf("END");
getch();
}