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;
    }

  • 相关阅读:
    SQL Server 2005 出现“此数据库没有有效所有者”错误的解决方法
    使用swfupload出现SecurityError Error #2156问题
    读取Excel表
    POJ 1953 (DP)
    POJ 1050 (DP)
    POJ 1276 (DP)
    POJ 1579 (DP)
    HDOJ 4223 (DP)
    POJ 1080 (DP)
    POJ 1458 (DP)
  • 原文地址:https://www.cnblogs.com/batman425/p/3282087.html
Copyright © 2011-2022 走看看