• 2008秋计算机软件基础多关键字排序


    /* 多关键字排序:
      先按总分由高到低排序,若总分相同则按数学成绩由高到低排序
    ,若总分和数学成绩都相同,则按英语成绩由高到低排序。
     
    */
    #include 
    <stdio.h>
    struct student
    {
      
    int xuehao;
      
    char xingming[10];
      
    int shuxue;
      
    int yingyu;
      
    int yuwen;
      
    int zongfen;
    };
    typedef 
    struct student S;

    void shuruchengji(S a[], int L)
    {
       
    /*elements are stored in a[1] to a[L]*/
       a[
    1].xuehao=101;
       strcpy(a[
    1].xingming,"a1");
       a[
    1].shuxue=80;
       a[
    1].yingyu=80;
       a[
    1].yuwen=80;
       a[
    1].zongfen=240;

       a[
    2].xuehao=102;
       strcpy(a[
    2].xingming,"a2");
       a[
    2].shuxue=70;
       a[
    2].yingyu=70;
       a[
    2].yuwen=70;
       a[
    2].zongfen=210;
       
       a[
    3].xuehao=103;
       strcpy(a[
    3].xingming,"a3");
       a[
    3].shuxue=90;
       a[
    3].yingyu=80;
       a[
    3].yuwen=70;
       a[
    3].zongfen=240;

       a[
    4].xuehao=104;
       strcpy(a[
    4].xingming,"a4");
       a[
    4].shuxue=90;
       a[
    4].yingyu=70;
       a[
    4].yuwen=80;
       a[
    4].zongfen=240;
    }

    void bubblesortYingYu(S r[],int n)
     { 
    /*elements are stored in r[1] to r[n]*/
      
    int i,j,flag;
      S temp;
      flag
    =1;
      i
    =1;
      
    while((i<n)) /*外循环控制排序的总趟数*/
       { 
          
    for(j=n;j>i;j--/*内循环控制一趟排序的进行*/ 
              
    if(r[j].yingyu>r[j-1].yingyu)  /*相邻元素进行比较,若逆序就交换*/
               {         
                  temp
    =r[j];
                  r[j]
    =r[j-1];
                  r[j
    -1]=temp;
               }
          i
    ++;
        }
    }

    void bubblesortShuXue(S r[],int n)
     { 
    /*elements are stored in r[1] to r[n]*/
      
    int i,j,flag;
      S temp;
      flag
    =1;
      i
    =1;
      
    while((i<n)) /*外循环控制排序的总趟数*/
       { 
          
    for(j=n;j>i;j--/*内循环控制一趟排序的进行*/ 
              
    if(r[j].shuxue>r[j-1].shuxue)  /*相邻元素进行比较,若逆序就交换*/
               {         
                  temp
    =r[j];
                  r[j]
    =r[j-1];
                  r[j
    -1]=temp;
               }
          i
    ++;
        }
    }

    void bubblesortZongFen(S r[],int n)
     { 
    /*elements are stored in r[1] to r[n]*/
      
    int i,j,flag;
      S temp;
      flag
    =1;
      i
    =1;
      
    while((i<n)) /*外循环控制排序的总趟数*/
       { 
          
    for(j=n;j>i;j--/*内循环控制一趟排序的进行*/ 
              
    if(r[j].zongfen>r[j-1].zongfen)  /*相邻元素进行比较,若逆序就交换*/
               {         
                  temp
    =r[j];
                  r[j]
    =r[j-1];
                  r[j
    -1]=temp;
               }
          i
    ++;
        }
    }

    void xianshi(S a[], int L)
    {
      
    int i;
      
    for(i=1;i<=L;i++)
          printf(
    " %d %s %d %d %d %d \n",
          a[i].xuehao,a[i].xingming,a[i].shuxue,
          a[i].yingyu, a[i].yuwen, a[i].zongfen);
    }

    void main()
    {

      S a[
    5];
      shuruchengji(a,
    4);
      bubblesortYingYu(a,
    4);
      bubblesortShuXue(a,
    4);
      bubblesortZongFen(a,
    4);
      xianshi(a,
    4);
      getchar();
    }

    结构体数组排序,作者:EmanLee。

  • 相关阅读:
    MapReduce学习总结之简介
    Hive Cli相关操作
    使用Hive UDF和GeoIP库为Hive加入IP识别功能
    Google Maps-IP地址的可视化查询
    hive多表联合查询(GroupLens->Users,Movies,Ratings表)
    云计算平台管理的三大利器Nagios、Ganglia和Splunk
    机器大数据也离不开Hadoop
    hive与hbase的整合
    hive优化之------控制hive任务中的map数和reduce数
    Hadoop管理员的十个最佳实践(转)
  • 原文地址:https://www.cnblogs.com/emanlee/p/1316684.html
Copyright © 2020-2023  润新知