码迷,mamicode.com
首页 > 编程语言 > 详细

qsort () -- 字符数组

时间:2014-11-05 12:50:43      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   os   for   sp   div   

 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数组放入结构体将其排序;

qsort () -- 字符数组

标签:style   blog   io   color   ar   os   for   sp   div   

原文地址:http://www.cnblogs.com/coutendl/p/4075851.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!