style: format code

This commit is contained in:
yanglbme
2019-08-21 10:10:08 +08:00
parent abc0d365de
commit 69ddc9fc52
101 changed files with 3154 additions and 2984 deletions

View File

@@ -1,44 +1,41 @@
// C++ Program for counting sort
// C++ Program for counting sort
#include <iostream>
using namespace std;
void countSort(string arr)
{
void countSort(string arr)
{
string output;
int count[256], i;
for(int i=0;i<256;i++)
count[i]=0;
for(i = 0; arr[i]; ++i)
++count[arr[i]];
for (i = 1; i <= 256; ++i)
count[i] += count[i-1];
for (i = 0; arr[i]; ++i)
{
output[count[arr[i]]-1] = arr[i];
--count[arr[i]];
}
int count[256], i;
for (int i = 0; i < 256; i++)
count[i] = 0;
for (i = 0; arr[i]; ++i)
arr[i] = output[i];
cout<<"Sorted character array is "<<arr;
}
int main()
{
for (i = 0; arr[i]; ++i)
++count[arr[i]];
for (i = 1; i <= 256; ++i)
count[i] += count[i - 1];
for (i = 0; arr[i]; ++i)
{
output[count[arr[i]] - 1] = arr[i];
--count[arr[i]];
}
for (i = 0; arr[i]; ++i)
arr[i] = output[i];
cout << "Sorted character array is " << arr;
}
int main()
{
string arr;
cin>>arr;
countSort(arr);
return 0;
}
cin >> arr;
countSort(arr);
return 0;
}