radix sort in c 2b 2b

Solutions on MaxInterview for radix sort in c 2b 2b by the best coders in the world

showing results for - "radix sort in c 2b 2b"
Arturo
08 Apr 2016
1#include <iostream> 
2using namespace std; 
3  
4
5int getMax(int arr[], int n) 
6{ 
7    int mx = arr[0]; 
8    for (int i = 1; i < n; i++) 
9        if (arr[i] > mx) 
10            mx = arr[i]; 
11    return mx; 
12} 
13  
14
15void countSort(int arr[], int n, int exp) 
16{ 
17    int output[n]; 
18    int i, count[10] = { 0 }; 
19  
20    
21    for (i = 0; i < n; i++) 
22        count[(arr[i] / exp) % 10]++; 
23  
24   
25    for (i = 1; i < 10; i++) 
26        count[i] += count[i - 1]; 
27  
28 
29    for (i = n - 1; i >= 0; i--) { 
30        output[count[(arr[i] / exp) % 10] - 1] = arr[i]; 
31        count[(arr[i] / exp) % 10]--; 
32    } 
33  
34    for (i = 0; i < n; i++) 
35        arr[i] = output[i]; 
36} 
37  
38
39
40void radixsort(int arr[], int n) 
41{ 
42
43    int m = getMax(arr, n); 
44  
45   
46    for (int exp = 1; m / exp > 0; exp *= 10) 
47        countSort(arr, n, exp); 
48} 
49  
50
51void print(int arr[], int n) 
52{ 
53    for (int i = 0; i < n; i++) 
54        cout << arr[i] << " "; 
55} 
56  
57
58int main() 
59{ 
60    int arr[] = { 170, 45, 75, 90, 802, 24, 2, 66 }; 
61    int n = sizeof(arr) / sizeof(arr[0]); 
62      
63
64      radixsort(arr, n); 
65    print(arr, n); 
66    return 0; 
67}
queries leading to this page
why shell sort count sort radix sort are not goodalgorithms to sort an array in descending order using radix sort technique compute the time and space complexity of your algorithmc 2b 2b radix sortalgorithm for radix sortradix sort cppinbuilt radix sort in c 2b 2bradix sort algorithm c 2b 2bradix sort javaradix sort time complexityapply radix sort on the given array of values show all passes on the given array 5bkeep i mind the ascii values 5d 2c all 5 steps arr 3d 7b10124 2c 00256 2c 11005 2c 10205 2c 90125 2c 32150 2c 23154 2c 20014 2c 00325 2c 65002 2c 14005 2c 89201 2c 74005 2c 56231 2c 85002 2c 65214 7d radix sort implementationradix sort c 2b 2bradix sort code in c 2b 2bc maximum radix sort using arrayjava radix sortradix sort example in pythonradix sort pythonradix sort cis it possible to use insertion sortin intermediate steps ofradix sort 3f justify your answerwith consequencesradix sort random array javaradix sort code in c 2b 2bradix sort tint arr 5b 5d 3d 7b 170 2c 45 2c 75 2c 90 2c 802 2c 24 2c 2 2c 66 7d 3bradix sort implradix sort in cradix sort c 2b 2bradix sort c 2b 2b stlradix sort algorithmradix sort program in c 2b 2bhow to do radix sort algorithm c 2b 2bradix sort in pythonradix sort c 2b 2b coderadix sort in cppprogram to implement the radix sort algorithm in c 2b 2ba 29 explain the algorithm to sort the elements using radix sort using linked allocation trace the algorithm for the following data 231 645 413 198 23 547 874 432 765 678 984 386 code for radix srotradix sort in c 2b 2bradix sort using averageradix sort c 2b 2b programradix sort in c 2b 2b without counting sortradix sort in javaradix sort array in cradix sorting in c 2b 2bradix sort in c 2b 2b