mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-14 10:50:13 +08:00
style: format code
This commit is contained in:
@@ -3,58 +3,66 @@
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
void radixsort(int a[],int n){
|
||||
void radixsort(int a[], int n)
|
||||
{
|
||||
int count[10];
|
||||
int output[n];
|
||||
memset(output,0,sizeof(output));
|
||||
memset(count,0,sizeof(count));
|
||||
memset(output, 0, sizeof(output));
|
||||
memset(count, 0, sizeof(count));
|
||||
int max = 0;
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
if (a[i]>max)
|
||||
if (a[i] > max)
|
||||
{
|
||||
max = a[i];
|
||||
}
|
||||
}
|
||||
int maxdigits = 0;
|
||||
while(max){
|
||||
while (max)
|
||||
{
|
||||
maxdigits++;
|
||||
max/=10;
|
||||
max /= 10;
|
||||
}
|
||||
for(int j=0;j<maxdigits;j++){
|
||||
for(int i=0;i<n;i++){
|
||||
int t = pow(10,j);
|
||||
count[(a[i]%(10*t))/t]++;
|
||||
for (int j = 0; j < maxdigits; j++)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int t = pow(10, j);
|
||||
count[(a[i] % (10 * t)) / t]++;
|
||||
}
|
||||
int k = 0;
|
||||
for(int p=0;p<10;p++){
|
||||
for(int i=0;i<n;i++){
|
||||
int t = pow(10,j);
|
||||
if((a[i]%(10*t))/t==p){
|
||||
for (int p = 0; p < 10; p++)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
int t = pow(10, j);
|
||||
if ((a[i] % (10 * t)) / t == p)
|
||||
{
|
||||
output[k] = a[i];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
memset(count,0,sizeof(count));
|
||||
memset(count, 0, sizeof(count));
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
a[i] = output[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
void print(int a[],int n){
|
||||
void print(int a[], int n)
|
||||
{
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
cout<<a[i]<<" ";
|
||||
cout << a[i] << " ";
|
||||
}
|
||||
cout<<endl;
|
||||
cout << endl;
|
||||
}
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int a[] = {170, 45, 75, 90, 802, 24, 2, 66};
|
||||
int n = sizeof(a)/sizeof(a[0]);
|
||||
radixsort(a,n);
|
||||
print(a,n);
|
||||
int n = sizeof(a) / sizeof(a[0]);
|
||||
radixsort(a, n);
|
||||
print(a, n);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user