• 简单选择排序(Simple Selection Sort)的C语言实现


    简单选择排序(Simple Selection Sort)的核心思想是每次选择无序序列最小的数放在有序序列最后

     

    演示实例:

    C语言实现(编译器Dev-c++5.4.0,源代码后缀.cpp)

    原创文章,转载请注明来自钢铁侠Mac博客http://www.cnblogs.com/gangtiexia

     1 #include <stdio.h>
     2 #define LEN 6
     3 
     4 typedef float keyType;
     5 
     6 typedef struct{
     7     keyType score;
     8     char name[20];
     9 }student;
    10 
    11 typedef struct{
    12     int length=LEN;
    13     student stu[LEN];
    14 }sqList;
    15 
    16 int selectMax(sqList &L,int i){
    17     int max;
    18     keyType maxScore=L.stu[i].score;
    19     for(max=i;i<L.length;i++)
    20         if(maxScore<L.stu[i].score)
    21             max=i;
    22     
    23     return max;
    24 }
    25 
    26 void simpleSS(sqList &L){
    27     int max;
    28     for(int i=1;i<L.length;i++)
    29         {
    30             max=selectMax(L,i);
    31             student temp=L.stu[max];
    32             L.stu[max]=L.stu[i];
    33             L.stu[i]=temp;
    34         }
    35 }
    36 
    37 int main(){
    38     sqList L;
    39 
    40     for(int i=1;i<L.length;i++){
    41         printf("
    请输入第%d个学生的姓名:",i);
    42         gets(L.stu[i].name);
    43         printf("分数:");
    44         scanf("%f",&(L.stu[i].score));
    45         getchar();
    46     }    
    47     
    48     simpleSS(L);
    49     
    50     for(int i=1;i<L.length;i++){
    51         printf("
    学生%s 分数%f 第%d名",L.stu[i].name,L.stu[i].score,i);
    52     }
    53     return 1;
    54 }

     

  • 相关阅读:
    scrapy相关信息
    BeautifulSoup常见使用
    requests常用模块以及爬取github个人项目
    django rest framework 与前端跨域问题解决
    nginx配置正向代理与反向代理
    django+nginx+uwsgi+https
    linux基本命令
    python基本算法
    centos7配置ftp服务器
    nginx1.12配置
  • 原文地址:https://www.cnblogs.com/gangtiexia/p/5097212.html
Copyright © 2020-2023  润新知