栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++完成快速排序及其它基本操作

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++完成快速排序及其它基本操作

//分别利用快速排序实现学生成绩管理, 实现以下数据的总成绩、数学成绩的排序。

#include
#include
#include 
#include
using namespace std;

typedef struct
    {   int   	 num;      		//学号
        float    yw;			//语文 
        float    key;			//数学 
        float    yy;			//英语 
        float    sum;			//总分 
    }student1;

typedef struct
    {   int   	 num;      		//学号
        float    yw;			//语文 
        float    sx;			//数学 
        float    yy;			//英语 
        float    key;			//总分 
    }student2;


template
int partition(ElementType element[],int low,int high)
{	int standardkey;
	ElementType temp;
	temp=element[low];
	standardkey=temp.key;
	while(low=standardkey)
		{	high--;
		}
		if(low
void Qsort(ElementType element[],int low,int high)
{	int standardlocation;
	if(low
void Quicksort(ElementType element[],int n)
{	Qsort(element,0,n-1);
}


int main()
{	student1 s0,s1,s2,s3,s4,s5,s6,s7,s8,s9;
	student2 S0,S1,S2,S3,S4,S5,S6,S7,S8,S9;
	
	s1={20010008,88.0,94.0,90.5,272.5};
	s2={20010004,85.0,87.0,96.5,268.5};
	s3={20010005,96.0,93.0,100.0,289.0};
	s4={20010006,72.0,76.0,70.5,218.5};
	s5={20010001,85.0,88.0,97.0,270.0};
	s6={20010002,92.5,91.0,95.0,278.5};
	s7={20010003,95.0,98.0,99.0,292.0};
	s8={20010007,65.0,53.0,53.0,171.0};
	s9={20010009,96.5,83.0,65.0,244.5};
	
	S1={20010008,88.0,94.0,90.5,272.5};
	S2={20010004,85.0,87.0,96.5,268.5};
	S3={20010005,96.0,93.0,100.0,289.0};
	S4={20010006,72.0,76.0,70.5,218.5};
	S5={20010001,85.0,88.0,97.0,270.0};
	S6={20010002,92.5,91.0,95.0,278.5};
	S7={20010003,95.0,98.0,99.0,292.0};
	S8={20010007,65.0,53.0,53.0,171.0};
	S9={20010009,96.5,83.0,65.0,244.5};
	
	student1 a[10]={s0,s1,s2,s3,s4,s5,s6,s7,s8,s9};
	student2 b[10]={S0,S1,S2,S3,S4,S5,S6,S7,S8,S9};	

	cout<<"按数学成绩排序:"<<'n';	
	Quicksort(a,10);
	cout< 

ps:关键代码主要参考《数据结构》课本,非本人原创。

pps:代码写的匆忙,可能稍有瑕疵(…比如编译的时候会有warning等),敬请见谅。

学生成绩示意:

 

运行结果示意:

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/983502.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号