【C语言】选择排序算法-习题

【C语⾔】选择排序算法-习题
雅安市委书记徐孟加#include <stdio.h>
#include <stdlib.h>
/*C语⾔程序设计案例教程(廖湖声) P122 第四章上机练习第⼀题*/
/*北⼯⼤896 计算机*/
/*选择排序*/
int select(int num[],int count[]){
int i,j,max,temp_num,temp_count;
for(i=0;i<99;i++){
max=i;
for(j=i+1;j<100;j++){
if(count[j]>count[max]){
max=j;
}
}
if(max!=i){
/*交换num*/
temp_num=num[i];
num[i]=num[max];
num[max]=temp_num;
/*交换count*/微调
temp_count=count[i];
count[i]=count[max];
count[max]=temp_count;
新宽联
}
}
}
int main()
{
int num[100];
int count[100];英国海外志愿服务社
int i;
/*⽣成待排序列*/
for(i=0;i<100;i++){
num[i]=i+1;
count[i]=rand()%100;
}
select(num,count);//选择排序函数
/*打印结果*/
printf("Top 10(order by download times):\n");
for(i=0;i<10;i++){北工大
printf("number:%d,download times:%d\n",num[i],count[i]);
}
printf("\n");
printf("Never been download:\n");
for(i=0;i<100;i++){
if(count[i]==0)
printf("number:%d,download times:%d\n",num[i],count[i]);
刘智仁}
return0;
}

本文发布于:2024-09-23 11:11:09,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/719748.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:选择   排序   程序设计   英国   雅安   练习
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议