Internal ordering of strings
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace Std;
BOOL CMP (char Str1,char str2) {
Return str1<str2;
}
int main () {
String str;
cin>>str;
Sort (Str.begin (), Str.end (), CMP);
cout<<str;
return 0;
}
Structure sort
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace Std;
struct node{
int num;
String str;
}ND[10];
int CMP (node N1,node n2) {
if (n1.num!=n2.num)
Return n1.num<n2.num;
else if (N1.str.compare (N2.STR) <0)
return 1;
Else
return 0;
}
int main () {
for (int i =0;i<3;i++) {
cin>>nd[i].num>>nd[i].str;
}
Sort (nd,nd+3,cmp);
for (int J =0;j<3;j++) {
cout<<nd[j].num<< "" <<nd[j].str<<endl;
}
return 0;
}
Array sorting
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace Std;
int cmp (int n1,int n2) {
Return n1<n2;
}
int main () {
int num[10];
for (int i =0;i<5;i++) {
cin>>num[i];
}
Sort (num,num+5,cmp);
for (int J =0;j<5;j++) {
cout<<num[j]<< "";
}
return 0;
}
C + + Sort sort