add markdown identifier to code language (#36503)
This commit is contained in:
committed by
Randell Dawson
parent
590438ecfa
commit
dd3c0e0893
@ -66,40 +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.
|
The array becomes : 10, 11, 17, 21, 34, 44, 123, 654 which is sorted. This is how our algorithm works.
|
||||||
|
|
||||||
An implementation in C:
|
An implementation in C:
|
||||||
```
|
```c
|
||||||
void countsort(int arr[],int n,int place){
|
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 output[n];
|
||||||
|
|
||||||
int i,freq[range]={0}; //range for integers is 10 as digits range from 0-9
|
for(i=0;i<n;i++)
|
||||||
int output[n];
|
freq[(arr[i]/place)%range]++;
|
||||||
|
|
||||||
for(i=0;i<n;i++)
|
for(i=1;i<range;i++)
|
||||||
freq[(arr[i]/place)%range]++;
|
freq[i]+=freq[i-1];
|
||||||
|
|
||||||
for(i=1;i<range;i++)
|
for(i=n-1;i>=0;i--){
|
||||||
freq[i]+=freq[i-1];
|
output[freq[(arr[i]/place)%range]-1]=arr[i];
|
||||||
|
freq[(arr[i]/place)%range]--;
|
||||||
for(i=n-1;i>=0;i--){
|
}
|
||||||
output[freq[(arr[i]/place)%range]-1]=arr[i];
|
|
||||||
freq[(arr[i]/place)%range]--;
|
for(i=0;i<n;i++)
|
||||||
}
|
arr[i]=output[i];
|
||||||
|
|
||||||
for(i=0;i<n;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;
|
||||||
int mul=1;
|
while(maxx){
|
||||||
while(maxx){
|
countsort(arr,n,mul);
|
||||||
countsort(arr,n,mul);
|
mul*=10;
|
||||||
mul*=10;
|
maxx/=10;
|
||||||
maxx/=10;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
An implementation in python :
|
An implementation in python :
|
||||||
|
|
||||||
```
|
```py
|
||||||
def counting_sort(arr, max_value, get_index):
|
def counting_sort(arr, max_value, get_index):
|
||||||
counts = [0] * max_value
|
counts = [0] * max_value
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user