如何排序 ?? 谢谢你的回复

c_340705108 2011-09-21 10:37:26
完成程序,实现对数组的降序排序
#include<stdio.h>
void sort();
int main()
{
int arry[]={23,45,56,2,56,1,3,76,89,343};//数字任意
sort();
return 0;
}

void sort()
{
________________________________________-
||
||
|...................................................................|
}
...全文
115 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
Fenice 2011-09-23
  • 打赏
  • 举报
回复
冒泡或者插入
c_340705108 2011-09-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dizuo 的回复:]
百度 各种排序算法啊。
[/Quote]

sort() 中 是没有参数的,怎么得到arry的地址????
c_340705108 2011-09-22
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 zhao4zhong1 的回复:]
用qsort函数
[/Quote]


sort() 中是没有参数的!! 怎么得到arry的地址???
c_340705108 2011-09-22
  • 打赏
  • 举报
回复
回复大家, sort中 是没有参数的! 这是sony 前天的一道面试题目!! 我不知道 怎么得到arry的地址?? 谢谢大家真么热心
hongwenjun 2011-09-21
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int int_compare(const void* a, const void* b)
{
return (*(int*)a - * (int*)b);
}
int char_compare(const void* a, const void* b)
{
return (*(char*)a - * (char*)b);
}

void int_sort(int* beg , int* end)
{
qsort(beg, end - beg , sizeof(int), int_compare);
}

void char_sort(char* beg , char* end)
{
qsort(beg, end - beg , sizeof(char), char_compare);
}

int main()
{
int arry[] = {23, 45, 56, 2, 56, 1, 3, 76, 89, 343}; //数字任意
int_sort(arry, arry + 10);
for (int n = 0; n != 10; n++)
printf("%d ", arry[n]);

char str[] = "int char_compare(const void* a, const void* b)";
char_sort(str, str + strlen(str));
printf("\n%s \n", str);
return 0;
}

C语言用下包装也可以,
C++ 就直接用 STL的算法方便了
rendao0563 2011-09-21
  • 打赏
  • 举报
回复


#include <functional>
#include <algorithm>

int main(int argc, char* argv[])
{
int arry[]={23,45,56,2,56,1,3,76,89,343};//数字任意

std::sort(&arry[0], &arry[sizeof(arry) / sizeof(arry[0])] , std::greater<int>());
return 0;
}
rendao0563 2011-09-21
  • 打赏
  • 举报
回复
既然是C++ 为啥不直接sort


#include <algorithm>

int main(int argc, char* argv[])
{
int arry[]={23,45,56,2,56,1,3,76,89,343};//数字任意

std::sort(&arry[0], &arry[sizeof(arry) / sizeof(arry[0])]);
return 0;
}
hongwenjun 2011-09-21
  • 打赏
  • 举报
回复
/* qsort example */
#include <stdio.h>
#include <stdlib.h>

int values[] = { 40, 10, 100, 90, 20, 25 };

int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}

int main ()
{
int n;
qsort (values, 6, sizeof(int), compare);
for (n=0; n<6; n++)
printf ("%d ",values[n]);
return 0;
}

如果嫌qsort不好用,就用STL里泛型算法 sort,或者自己包装一下
codesnail 2011-09-21
  • 打赏
  • 举报
回复
google是最好的老师。
赵4老师 2011-09-21
  • 打赏
  • 举报
回复
用qsort函数
yoyojoyinyin 2011-09-21
  • 打赏
  • 举报
回复
没得冒泡了!来看看高手怎么回答
xpston008 2011-09-21
  • 打赏
  • 举报
回复
插到到数据库中 排序后 再查出来。

最馊的主意

Q446512799 2011-09-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 songy193184 的回复:]
用指针
[/Quote]
算法就用冒泡吧
crystalzheng 2011-09-21
  • 打赏
  • 举报
回复
lz看来初学啊,百度冒泡排序或者选择排序,非常容易理解的。
LBJMD 2011-09-21
  • 打赏
  • 举报
回复
冒泡法,选择排序法,各种方法都行啊,多自己看点书吧。
luciferisnotsatan 2011-09-21
  • 打赏
  • 举报
回复
sort都没参数,该不会从函数里越界回去排吧。
bdmh 2011-09-21
  • 打赏
  • 举报
回复
如果需要降序,自己改个判断条件就好了,大于改小于之类的
ryfdizuo 2011-09-21
  • 打赏
  • 举报
回复
百度 各种排序算法啊。
bdmh 2011-09-21
  • 打赏
  • 举报
回复
你没事吧,数组排序,百度太多了,代码copy过来就能用
http://blog.csdn.net/bdmh/article/details/6049252
songy193184 2011-09-21
  • 打赏
  • 举报
回复
用指针

65,189

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧