• 【2017-3-1】冒泡排序


    冒泡排序

    依次比较相邻的两个数,将小数放在前面,大数放在后面。

    数组中两个变量进行交换                                         //对数组中两个变量进行交换,是冒泡排序中最基本的步骤

             int [] s = new int[]{1,5,7};

             int  a = s [0]; 

             s [0] = s [s.Length-1];

             s [s.Length-1] = int a ;

             for (int i =0;i<s.Length;i++);

             { 

                     Console.WriteLine(s[i]);

              }

        冒泡排序                                                                //冒泡排序最基本的格式,格式固定,很重要,记住                                                

                        int [ ] ss = new int[ ]{2,1,5,3,4};

                        int  temp;

                        for ( int i = 0 ; i < ss.Length ; i ++ )                    //抽取第一个变量    

                       {

                            for ( int j = i + 1 ; j < ss.Length ; j++  )           // 抽取第二个变量             

                            {

                                  if ( ss[ i ]< ss[ j ]    )                                //比较,交换位置

                                  {

                                         temp = ss[ i ];                                     

                                         ss[ i ]= ss[ j ];

                                         ss[ j ];=temp;

                                    }

                              }

                          }

                          for( int i <0 ; i< ss.Length ; i++ )                         // 输出 

                        {

                             Console.WriteLine(  ss [ i ] );

                          }

                          Console.ReadLine();

  • 相关阅读:
    BZOJ 3144 [Hnoi2013]切糕
    一场比赛:20170707
    BZOJ 2815 [ZJOI2012]灾难
    BZOJ 1088 [SCOI2005]扫雷Mine
    BZOJ 1052 [HAOI2007]覆盖问题
    BZOJ 3505 [Cqoi2014]数三角形
    BZOJ 2957 楼房重建
    BZOJ 2654 tree
    丁酉年六月十一ACM模拟赛
    BZOJ 3438 小M的作物 & BZOJ 1877 [SDOI2009]晨跑
  • 原文地址:https://www.cnblogs.com/hanqi0216/p/6525768.html
Copyright © 2020-2023  润新知