fix(guide): radix sort formatting/inconsistencies (#36507)

* fix(guide): radix sort formatting/inconsistencies

Signed-off-by: Jonathan <theflametrooper@gmail.com>

* fix(guide): radix sort spacing should be 2 spaces

Signed-off-by: Jonathan <theflametrooper@gmail.com>
This commit is contained in:
Jonathan Graham
2019-07-29 02:58:07 +01:00
committed by Randell Dawson
parent ba6ae7154c
commit 04e98783cd
6 changed files with 268 additions and 193 deletions

View File

@@ -66,36 +66,38 @@ Finally , we sort according to the hundred's digit (most significant digit):
The array becomes : 10, 11, 17, 21, 34, 44, 123, 654 which is sorted. This is how our algorithm works.
An implementation in C:
```c
void countsort(int arr[],int n,int place){
int i,freq[range]={0}; //range for integers is 10 as digits range from 0-9
int i,freq[range]={0}; // range for integers is 10 as digits range from 0-9
int output[n];
for(i=0;i<n;i++)
freq[(arr[i]/place)%range]++;
freq[(arr[i]/place)%range]++;
for(i=1;i<range;i++)
freq[i]+=freq[i-1];
freq[i]+=freq[i-1];
for(i=n-1;i>=0;i--){
output[freq[(arr[i]/place)%range]-1]=arr[i];
freq[(arr[i]/place)%range]--;
output[freq[(arr[i]/place)%range]-1]=arr[i];
freq[(arr[i]/place)%range]--;
}
for(i=0;i<n;i++)
arr[i]=output[i];
arr[i]=output[i];
}
void radixsort(ll arr[],int n,int maxx){ //maxx is the maximum element in the array
void radixsort(ll arr[],int n,int maxx){ // maxx is the maximum element in the array
int mul=1;
while(maxx){
countsort(arr,n,mul);
mul*=10;
maxx/=10;
}
countsort(arr,n,mul);
mul*=10;
maxx/=10;
}
}
```
An implementation in python :
An implementation in Python:
```py
def counting_sort(arr, max_value, get_index):
@@ -128,7 +130,7 @@ def counting_sort(arr, max_value, get_index):
return ret
```
### More Information:
### More Information
- [Wikipedia](https://en.wikipedia.org/wiki/Radix_sort)