zoukankan      html  css  js  c++  java
  • 冒泡排序 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     } 

    乌龟才背着房子过一辈子
  • 相关阅读:
    强制开启Android webview debug模式
    JavaScript DOM操作案例自定义属性的设置跟获取
    JavaScript innerText跟innerHTML的区别
    JavaScript DOM操作案例封装innerText跟textContent函数(浏览器兼容)
    JavaScript其他获取元素的方式
    JavaScript DOM操作案例根据类样式的名字获取元素
    JavaScript DOM操作案例根据name属性获取元素
    Java throws 使用
    理解 Android Build 系统
    理解Android编译命令
  • 原文地址:https://www.cnblogs.com/Yellowshorts/p/3083596.html
Copyright © 2011-2022 走看看