zoukankan      html  css  js  c++  java
  • 冒泡排序

    #include "stdafx.h"
    #include "stdio.h"
    #include "string.h"

    struct persion
    {
     int Height;
     int power;
     int Iq;
    };

    typedef struct persion Boy;

    void InitBoy(Boy *boys)
    {
     boys[0].Height=172;
     boys[0].power=90;
     boys[0].Iq=80;

     boys[1].Height=162;
     boys[1].power=97;
     boys[1].Iq=70;

     boys[2].Height=182;
     boys[2].power=70;
     boys[2].Iq=50;
    }

    void MaoPaoSort1(Boy *boys)
    {
     int i,j;
     Boy temp;
     for(i=0;i<2;i++)
      for (j=i+1;j<3;j++)
      {
       if (boys[i].Height>boys[j].Height)
       {
        temp=boys[i];
        boys[i]=boys[j];
        boys[j]=temp;
       } 
      }
    }

    void MaoPaoSort2(Boy *boys)
    {
     int i,j;
     Boy temp;
     for(i=0;i<2;i++)
      for (j=0;j<2-i;j++)
      {
       if (boys[j].Height>boys[j+1].Height)
       {
        temp=boys[j];
        boys[j]=boys[j+1];
        boys[j+1]=temp;
       }
      }
    }

    void display(Boy *boys)
    {
     for (int i=0;i<3;i++)
     {
      printf("%d %d  %d ",boys[i].Height,boys[i].power,boys[i].Iq);
     }
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
     Boy boys[3];
     InitBoy(boys);
     MaoPaoSort2(boys);
     display(boys);
     getchar();
     return 0;
    }

  • 相关阅读:
    Django——文件上传
    Django——视图基础
    Django——模板基础
    Django——路由基础
    Django——用户认证系统
    Django——form表单
    Django——模型基础(多表)
    Django——模型基础(单表)
    Django博客项目
    黏包
  • 原文地址:https://www.cnblogs.com/batman425/p/3282087.html
Copyright © 2011-2022 走看看