Radix Sort
Radix Sort
#include <iostream>
#include <vector>
max = arr[i];
return max;
int n = arr.size();
vector<int> output(n);
count[index]++;
output[count[index] - 1] = arr[i];
count[index]--;
arr[i] = output[i];
countingSort(arr, exp);
int main() {
int n;
cin >> n;
vector<int> arr(n);
cout << "Enter " << n << " elements:" << endl;
radixSort(arr);
return 0;
1. Start.
4. Find the maximum number in the array to determine the number of digits.
5. Perform the following steps for each digit place (ones, tens, hundreds, etc.):
o Initialize a stable sorting mechanism (e.g., counting sort) for the current digit place.
o Sort the elements of the array based on the current digit using counting sort.
8. End.
PSEUDOCODE:::::
Function getMax(array, n)
max = array[0]
For i = 1 to n-1
max = array[i]
EndIf
EndFor
Return max
EndFunction
For i = 0 to n-1
index = (array[i] / exp) % 10
count[index] = count[index] + 1
EndFor
For i = 1 to 9
EndFor
For i = n-1 to 0
output[count[index] - 1] = array[i]
count[index] = count[index] - 1
EndFor
For i = 0 to n-1
array[i] = output[i]
EndFor
EndFunction
Function radixSort(array, n)
max = getMax(array, n)
exp = 1
countingSort(array, n, exp)
exp = exp * 10
EndWhile
EndFunction
Main
Input n
Declare array[n]
For i = 0 to n-1
Input array[i]
EndFor
Call radixSort(array, n)
For i = 0 to n-1
Print array[i]
EndFor
EndMain