Skip to content

Commit 2cb0041

Browse files
committed
radix tried and tested with representative input
1 parent aa34286 commit 2cb0041

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

radix-sort.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ int B[10];
2626
int C[size];
2727
int D[size];
2828
int power=1;
29-
int total = 0;
29+
3030
while(power <= digits)//Get all the digits in the array
3131
{
32+
for(int n = 0; n < 10; ++n)
33+
{
34+
B[n] = 0;
35+
}
3236
for(int j=0; j<size; ++j)//Set digits
3337
{
3438
D[j] = (A[j]/((int)pow(10.0,power)))%10;
@@ -39,6 +43,7 @@ while(power <= digits)//Get all the digits in the array
3943
{
4044
B[D[k]]++;
4145
}
46+
int total = 0;
4247
for(int l=0; l<10; ++l)//Do the less than equal part.
4348
{
4449
int temp = B[l];
@@ -47,7 +52,7 @@ while(power <= digits)//Get all the digits in the array
4752
}
4853
for(int m=0; m<size; ++m)//Actual Sorting Here
4954
{
50-
C[B[D[m]]]=A[m];
55+
C[B[D[m]]] = A[m];
5156
++B[D[m]];
5257
}
5358
for(int n=0; n<size; ++n)//reset A with new sorted part
@@ -56,10 +61,7 @@ while(power <= digits)//Get all the digits in the array
5661
C[n] = 0;
5762
D[n] = 0;
5863
}
59-
for(int n = 0; n < 10; ++n)
60-
{
61-
B[n] = 0;
62-
}
64+
6365
++power;
6466
}
6567

0 commit comments

Comments
 (0)