-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRadixSorter.cpp
41 lines (32 loc) · 873 Bytes
/
RadixSorter.cpp
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
#include "RadixSorter.h"
#include <math.h>
RadixSorter::RadixSorter()
{
}
void RadixSorter::countingSort(QVector<int> &v, int digit){
QVector<int> counting(10, 0);
QVector<int> copy = v;
for (int i : v) {
int idx = (int)(i/pow(10,digit))%10;
counting[ idx ]++;
}
for (int i = 1; i < counting.size() ; i++) {
counting[i] = counting[i] + counting[i-1];
}
for (int i=copy.size()-1; i>=0 ; i--) {
waitInterval();
int idx = (int)(copy[i]/pow(10,digit))%10;
v[counting[idx]-1] = copy[i];
emit vectorChanged(counting[idx]-1) ;
counting[idx]--;
if(isInterruptionRequested())
return;
}
}
void RadixSorter::startSortingThread(){
int n = vector->size();
//Ordering digits
for(int d=0; d<3; d++){
countingSort(*vector, d);
}
}