-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.cpp
More file actions
82 lines (60 loc) · 1.56 KB
/
sort.cpp
File metadata and controls
82 lines (60 loc) · 1.56 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
#include <stdio.h>
#include <stdlib.h>
#include <string>
void heapsort()
{
}
void quicksort(int input[], int start,int end)
{
if ( start < end ){
int k = start;
int i = start + 1;
for ( ;i <= end; i++){
if ( input[i] < input[start] ){
int temp = input[++k];
input[k] = input[i];
input[i] = temp;
}
}
int temp = input[k];
input[k] = input[start];
input[start] = temp;
quicksort(input, start, k - 1);
quicksort(input, k + 1, end);
}
}
bool CountSort(char* input[], int num, int list)
{
//count as the list
int* count = new int[num];
if ( count == 0 )
return;
memset(count, 0 , num);
for( int i = 0 ; i < num; i++ ){
int value = input[i][list] - 'A';
count[value]++;
}
//count the position
for ( int i = num - 1;i >= 0 ; i--){
}
char* tmp[16] ;
delete[] count;
}
void RadixSort(char* input[], int num, int list)
{
for( int i = 2 ; i >= 0; i-- ){
if ( CountSort(input, num, i) == false )
return;
}
}
int main()
{
/*int input[10] = { 23,12,4,775,245,67,2,3,18,3};
quicksort(input, 0, 9);
for (int i = 0 ; i < 10; i++)
printf("%d, ",input[i]);*/
char* input[16] = {"COW", "DOG","SEA", "RUG", "ROW", "MOB", "BOX", "TAB",
"BAR", "EAR", "TAR", "DIG", "BIG", "TEA", "NOW", "FOX"};
RadixSort(input, 16, 3);
return 0;
}