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

@@ -7,58 +7,56 @@
//This Programme uses a comparator to sort the array in Numerical order instead of Alphanumeric order
#include<iostream>
#include<string>
#include<algorithm>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool NumericSort(string a,string b)
bool NumericSort(string a, string b)
{
while(a[0]=='0')
while (a[0] == '0')
{
a.erase(a.begin());
}
while(b[0]=='0')
while (b[0] == '0')
{
b.erase(b.begin());
}
int n=a.length();
int m=b.length();
if(n==m)
return a<b;
return n<m;
}
int n = a.length();
int m = b.length();
if (n == m)
return a < b;
return n < m;
}
int main()
{
int n;
cout << "Enter number of elements to be sorted Numerically\n";
cin >> n;
int n;
cout << "Enter number of elements to be sorted Numerically\n";
cin >> n;
vector<string> v(n);
cout << "Enter the string of Numbers\n";
for(int i=0;i<n;i++)
{
cin >> v[i];
}
sort(v.begin(),v.end());
cout << "Elements sorted normally \n";
for(int i=0;i<n;i++)
{
cout << v[i] << " ";
}
cout << "\n";
sort(v.begin(),v.end(),NumericSort);
cout << "Elements sorted Numerically \n";
for(int i=0;i<n;i++)
{
cout << v[i] << " ";
}
return 0;
vector<string> v(n);
cout << "Enter the string of Numbers\n";
for (int i = 0; i < n; i++)
{
cin >> v[i];
}
sort(v.begin(), v.end());
cout << "Elements sorted normally \n";
for (int i = 0; i < n; i++)
{
cout << v[i] << " ";
}
cout << "\n";
sort(v.begin(), v.end(), NumericSort);
cout << "Elements sorted Numerically \n";
for (int i = 0; i < n; i++)
{
cout << v[i] << " ";
}
return 0;
}