zoukankan      html  css  js  c++  java
  • 简单选择排序(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 }

     

  • 相关阅读:
    深入理解java异常处理机制
    i2c总线
    运行时类型识别(RTTI)
    bcg界面库总结
    c++ 虚函数表
    宽字符,宽字符串
    c++异常处理
    内存管理
    c++中使用联合体
    MFC自定义消息
  • 原文地址:https://www.cnblogs.com/gangtiexia/p/5097212.html
Copyright © 2011-2022 走看看