C + + Sort sort

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.