-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadixsort.cpp
More file actions
85 lines (72 loc) · 1.77 KB
/
Copy pathRadixsort.cpp
File metadata and controls
85 lines (72 loc) · 1.77 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
// main.cpp
// lab05
//
// Created by Andres Rios on 3/14/19.
// Copyright © 2019 Andres Rios. All rights reserved.
//Last edited at 10:24 am
#include <iostream>
#include<deque>
using namespace std;
static int size;
//counting sort pesudo code
//assisted by daniel toriz
//collabed cristian ortiz
//help understanding radix sort from mark at pals
void countingsort(deque<int> A[], deque<int> B[],int pos){
int C[4];
//largest number of k can only be 3, therefore we need a size 4
//fixes issue with not not making array big enough
for (int i=0; i < 4; i++){
C[i]=0;
}
for (int j=0; j< size; j++){
C[A[j][pos]]=C[A[j][pos]]+1;
}
for (int i=1; i < 4; i++){
C[i]=C[i]+C[i-1];
}
for (int j = size-1; j>=0; j--){
//size-1 helped fixed issue
B[C[A[j][pos]] - 1] = A[j];
C[A[j][pos]]=C[A[j][pos]]-1;
}
}
/*int getd(int k){
int d;
//with base being 10
d = 10%k;
return d;
}*/
void radixsort(deque<int> A[], deque<int> B[]){
for(int pos = 9; pos>=0;pos--){
countingsort(A, B ,pos);
for(int i=0;i<size;i++){
A[i]=B[i];
}
}
//pos is 9 for the amount of colums starting at 0-9
//copy to the output array
}
int main(int argc, const char * argv[]) {
int k;
// cout<<endl;
cin>>size;
//deque<deque<int>>A;
deque<int>A[size];
deque<int>B[size];
for(int i=0; i<size; i++){
// deque<int>temp;
for(int j=0; j<10;j++){
cin>>k;
A[i].push_back(k);
//temp.push_back(k);
}
}
radixsort(A,B);
for(int i=0; i<size; i++){
for(int j=0; j<10;j++){
cout<<B[i][j]<<";";
}
cout<<endl;
}
}