• 冒泡排序 C#



     主程序入口

    class Program
        {
            static void Main(string[] args)
            {
                int[] iArrary = new int[] { 151361055992871234753347 };//定义数组
                BubbleSorter sh = new BubbleSorter();
                sh.Sort(iArrary);
                for (int m = 0; m < iArrary.Length; m++)//输出结果
                    Console.Write("{0} ", iArrary[m]);
                Console.ReadLine();
            }

        } 

    冒泡排序方法

     1  class BubbleSorter
     2     {
     3         /// <summary>
     4         /// 冒泡排序
     5         /// </summary>
     6         public void Sort(int[] list)
     7         {
     8             int i, j, temp;
     9             bool done = false;
    10             j = 1;
    11             while ((j < list.Length) && (!done))//判断长度
    12             {
    13                 done = true;
    14                 for (i = 0; i < list.Length - j; i++)
    15                 {
    16                     if (list[i] > list[i + 1])
    17                     {
    18                         done = false;
    19                         temp = list[i];
    20                         list[i] = list[i + 1];//交换数据
    21                         list[i + 1] = temp;
    22                     }
    23                 }
    24                 j++;
    25             }
    26         }

    27     } 

    乌龟才背着房子过一辈子
  • 相关阅读:
    CalISBN.java
    Int2BinaryString.java
    PrintNumber.java
    AllSame.java
    第一个程序
    将博客搬至CSDN
    sqoop 1.4.4-cdh5.1.2快速入门
    hadoop的关键进程
    HIVE快速入门
    公钥,私钥和数字签名这样最好理解
  • 原文地址:https://www.cnblogs.com/Yellowshorts/p/3083596.html
Copyright © 2020-2023  润新知