复制代码
对结构体字符串排序
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17百度找了好久都不能 最后问的学姐 解决啦 谢谢任真学姐啦 #include <stdio.h> #include <stdlib.h> #include <string.h> int cmp(const void *a,const void *b) { return strcmp((char *)a,(char *)b); } int main() { int i; char a[5][10]={"abcd","abc","abcde","feag","fdag"}; qsort(a,5,sizeof(a[0]),cmp); for(i=0;i<5;i++) puts(a[i]); return 0; }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { char w[11],d[11]; }dic[100005]; int cmp(const void *a,const void *b) { return strcmp((*(node *)a).d,(*(node *)b).d); } int main() { int i=0,j; char ch; while(1) { scanf("%s %s",dic[i].d,dic[i].w); getchar(),ch=getchar(); i++; if(ch=='n') break; } qsort(dic,i,sizeof(node),cmp); for(j=0;j<i;j++) printf("%sn",dic[j].d); }
最后
以上就是成就豆芽最近收集整理的关于qsort对数组字符串/结构体字符串排序的全部内容,更多相关qsort对数组字符串/结构体字符串排序内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复