求解---排序

zhjboss 2004-08-26 08:13:58
有记录,包括姓名、学号、分数三个字段,请用一种语言(c#/c++)编写,按分数从高到低排序,
...全文
167 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhjboss 2004-08-30
  • 打赏
  • 举报
回复
怎么没有c#开发人员来呢
zhjboss 2004-08-29
  • 打赏
  • 举报
回复
有 用c#的吗
rorot 2004-08-29
  • 打赏
  • 举报
回复
////////////////////////////////////////////////////////
//
// USEAGE -: Sort Student Information order by score
//
//////////////////////////////////////////////////////////

#include <map>
#include <functional>
#include <iostream>

struct student
{
student ( std::string name_, unsigned long id_, double score_ )
:name(name_), id(id_), score(score_) {}
std::string name;
unsigned long id;
double score;
};

int main()
{
std::map < double, student, std::greater<double> > smap;
typedef std::pair <double, student> spair;
smap.insert ( spair( 49.77, student( "Lily", 8547826, 49.77 ) ));
smap.insert ( spair( 92.34, student( "Tom", 1045896, 92.34 ) ));
smap.insert ( spair( 72.36, student( "Jack", 1023547, 72.36 ) ));
smap.insert ( spair( 83.52, student( "Lina", 5496587, 83.52 ) ));

for ( std::map<double, student>::iterator it = smap.begin();
it != smap.end();
++it )
std::cout << it->first << " --- " << (it->second).name << "\n";
return 0;
}
bamboo2000 2004-08-28
  • 打赏
  • 举报
回复
C#中没有指针,可以用数组啊
数据结构学得不好,听说堆排序速度很快
zhjboss 2004-08-28
  • 打赏
  • 举报
回复
怎么写啊
mskia 2004-08-28
  • 打赏
  • 举报
回复
定义一个类,然后重载运算符"( )"就可以了。
zhjboss 2004-08-27
  • 打赏
  • 举报
回复
yaos(等待WoW前玩私服吧·无心人) vv
采用箱排序,速度是O(n)的
怎么采用呢?我是一个初学者
yaos 2004-08-27
  • 打赏
  • 举报
回复
采用箱排序,速度是O(n)的
zhjboss 2004-08-27
  • 打赏
  • 举报
回复
有用c#的吗?因为c#没有指针
dext 2004-08-26
  • 打赏
  • 举报
回复
首先,你要排序的不是结构,而是指针,只意味着你需要一个指针数组。
编写一个Compare函数来确定结构之间的大小关系。

struct TScore {
char Name[10];
int ID;
float Mark;
}

int compare(TScore *s1, TScore s2) {
return (s1->Mark - s2->Mark);
};

然后调用标准过程 qsort()

对了,我用的是Borland C++ 3.1

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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