Skip to content

Commit 90e1c71

Browse files
committed
Now, radix LSD, plus selction changed in a bit of visualz
1 parent d252a9a commit 90e1c71

File tree

7 files changed

+47
-116
lines changed

7 files changed

+47
-116
lines changed

algorithm/category.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"quick": "Quicksort",
3232
"merge": "Mergesort",
3333
"heap" : "Heap Sort",
34-
"radixlsb" : "Radix LSB sort"
34+
"radixlsd" : "Radix LSD sort"
3535
}
3636
},
3737
"string": {

algorithm/category.json~

Lines changed: 0 additions & 49 deletions
This file was deleted.

algorithm/sorting/radixlsb/basic/code.js

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
tracer._print('original array = [' + D[0].join(', ') + ']');
2+
tracer._sleep(1000);
3+
tracer._pace(300);
4+
function pow(base, expo){
5+
var ans = 1;
6+
for(var i = 0; i < expo;i++){
7+
ans *= base;
8+
}
9+
return ans;
10+
}
11+
for(var exp = 0; exp < 6;exp ++){
12+
tracer._print("Bit "+exp);
13+
for(var i = 0; i < D[0].length; i++){
14+
tracer._select(0, i);
15+
D[2][ parseInt( D[0][i] / pow(10, exp) % 10) ] += 1;
16+
tracer._notify(2, parseInt( D[0][i] / pow(10, exp) % 10) );
17+
tracer._deselect(0, i);
18+
}
19+
for(var i = 1; i < 10; i++){
20+
tracer._select(2, i - 1);
21+
D[2][i] += D[2][i - 1];
22+
tracer._notify(2, i);
23+
tracer._deselect(2, i - 1);
24+
}
25+
for(var i = D[0].length - 1; i >= 0; i--){
26+
tracer._select(0, i);
27+
D[2][parseInt( D[0][i] / pow(10, exp) % 10) ] -= 1;
28+
tracer._notify(2, parseInt( D[0][i] / pow(10, exp) % 10) );
29+
D[1][ D[2][ parseInt( D[0][i] / pow(10, exp) % 10) ] ] = D[0][i];
30+
tracer._notify(1, D[2][ parseInt( D[0][i] / pow(10, exp) % 10) ] );
31+
tracer._deselect(0, i);
32+
}
33+
for(var i = 0; i < D[0].length; i++){
34+
tracer._select(1, i);
35+
D[0][i] = D[1][i];
36+
tracer._notify(0, i);
37+
tracer._deselect(1, i);
38+
}
39+
for(var i = 0; i < 10; i++){
40+
D[2][i] = 0;
41+
tracer._notify(2, i);
42+
}
43+
}
44+
tracer._print('sorted array = [' + D[0].join(', ') + ']');

algorithm/sorting/radixlsb/basic/data.js renamed to algorithm/sorting/radixlsd/basic/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ var k = [5,4,3,5,7,5,6,9];
33
var D = [
44
k,
55
Array1D.random(k.length),
6-
[0,0]
6+
[0,0,0,0,0,0,0,0,0,0]
77
];
88
tracer._setData(D);

algorithm/sorting/radixlsb/desc.json renamed to algorithm/sorting/radixlsd/desc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"Radix LSB Sort": "Radix sort is a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual bits which share the same significant position and value.",
2+
"Radix LSD Sort": "Radix sort is a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value.",
33
"Complexity": {
44
"time": "worst O(n), best O(n), average O(n)",
55
"space": "always O(n)"

algorithm/sorting/selection/basic/code.js~

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)