qsort () -- 字符数组

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<cmath>
 8 using namespace std;
 9 struct strx
10 {
11     char c[20];
12     int x;
13 } str[10010];
14 int cmp(const void*a,const void*b)
15 {
16     return  strcmp((*(strx*)a).c,(*(strx*)b).c);
17 }
18 
19 int main()
20 {
21     int n=-1;
22     while(cin>>str[++n].c);
23     qsort(str,n,sizeof(str[0]),cmp);
24     for(int i=0;i<n;i++)
25      cout<<str[i].c<<endl;
26     return 0;
27 }
/*这是将char数组放入结构体将其排序;

转载于:https://www.cnblogs.com/coutendl/p/4075851.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值