-
Notifications
You must be signed in to change notification settings - Fork 0
/
radixsort.c
52 lines (39 loc) · 960 Bytes
/
radixsort.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
#include <stdlib.h>
#include "sorting.h"
void radixsort(node_pointer* masterlist, int numdigits);
void distribute(node_pointer* masterlist, node_pointer* list, int i);
void coalesce(node_pointer* masterlist, node_pointer* list);
// 기수정렬을 수행하는 함수
void radixsort(node_pointer* masterlist, int numdigits) {
int i;
node_pointer list[10];
for (i = 1; i <= numdigits; i++) {
distribute(masterlist, list, i);
//coalesce(masterlist, list);
}
}
void distribute(node_pointer* masterlist, node_pointer* list, int i) {
int j;
node_pointer p;
for (j = 0; j <= 9; j++) {
list[i] = NULL;
}
p = *masterlist;
while (p != NULL) {
j = getDigit(p->key, i);
}
}
int getDigit(int num, int i) {
int j, ret;
j = 1;
while (j <= i) {
ret = num % 10;
num /= 10;
j++;
}
return ret;
}
void coalesce(node_pointer* masterlist, node_pointer* list) {
int j;
*masterlist = NULL;
}