qsort排序失败
这是我的代码这是我的测试结果各位大神求解释为什么会排序失败按道理来说不是升序就是降序偏偏这么奇葩
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int comp(const void *a,const void *b)
{
int c;
return c=((string *)a<=(string *)b?1:-1);
}
int main()
{
int a[7];
for(int x=0;x<7;x++)
cin>>a[x];
qsort(a,7,sizeof(int),comp);
qsort(a,7,sizeof(int),comp);
for(int x=0;x<7;x++)
cout<<a[x]<<" ";
return 0;
}
输入:7 6 5 4 3 2 1
输出:5 4 3 2 1 7 6 请按任意键继续. . .
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int comp(const void *a,const void *b)
{
int c;
return c=((string *)a<=(string *)b?1:-1);
}
int main()
{
int a[7];
for(int x=0;x<7;x++)
cin>>a[x];
qsort(a,7,sizeof(int),comp);
qsort(a,7,sizeof(int),comp);
for(int x=0;x<7;x++)
cout<<a[x]<<" ";
return 0;
}
输入:7 6 5 4 3 2 1
输出:5 4 3 2 1 7 6 请按任意键继续. . .
...全文
相关推荐
排序实验报告.doc
()、Bubble_sort()、QSort()和SelectSort()。
c语言函数库-第七章(其它函数).pdf
9. qsort函数:这是一个快速排序函数,用于对数组元素进行排序。
多进程实现快速排序(北京大学操作系统课程实习)
CreateProcess(NULL, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &siStartInfo, &piProcInfo)) { printf("创建子进程失败
C语言写的简易水果管理系统
知识点4:排序算法在本系统中,我们使用了qsort函数来对水果进行排序。我们定义了cmp_count_desc和cmp_price_desc两个比较函数,分别用于按数量和价格排序。
c语言-c语言编程基础之leetcode题解第18题四数之和.zip
注意,在实际使用时,还需要处理内存分配失败和结果数组的扩展等问题。


