"Radix Sort in c++" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "Radix Sort in c++" answered properly. Developers are finding an appropriate answer about Radix Sort in c++ related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like Radix Sort in c++. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on Radix Sort in c++.
Radix Sort in c++
#include <iostream>
using namespace std;
int getMax(int arr[], int n)
{
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}
void countSort(int arr[], int n, int exp)
{
int output[n];
int i, count[10] = { 0 };
for (i = 0; i < n; i++)
count[(arr[i] / exp) % 10]++;
for (i = 1; i < 10; i++)
count[i] += count[i - 1];
for (i = n - 1; i >= 0; i--) {
output[count[(arr[i] / exp) % 10] - 1] = arr[i];
count[(arr[i] / exp) % 10]--;
}
for (i = 0; i < n; i++)
arr[i] = output[i];
}
void radixsort(int arr[], int n)
{
int m = getMax(arr, n);
for (int exp = 1; m / exp > 0; exp *= 10)
countSort(arr, n, exp);
}
void print(int arr[], int n)
{
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
}
int main()
{
int arr[] = { 170, 45, 75, 90, 802, 24, 2, 66 };
int n = sizeof(arr) / sizeof(arr[0]);
radixsort(arr, n);
print(arr, n);
return 0;
}
All those coders who are working on the C++ based application and are stuck on Radix Sort in c++ can get a collection of related answers to their query. Programmers need to enter their query on Radix Sort in c++ related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about Radix Sort in c++ for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of Radix Sort in c++ while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "Radix Sort in c++". Visit this developer's friendly online web community, CodeProZone, and get your queries like Radix Sort in c++ resolved professionally and stay updated to the latest C++ updates.