• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 十行代碼搞定 "冒泡排序"

    發表于:2007-05-25來源:作者:點擊數: 標簽:代碼十行冒泡搞定排序
    十行代碼搞定 冒泡排序 選擇自 playyuer 的 Blog Java Code: class Class1 { static void bubbleSort(int[] a) { for (int j = a.length - 1; j 0; j--) // outer loop (backward) for (int i = 0; i j; i++) // inner loop (forward) if (a[i] a[i+1]) //Sw

    十行代碼搞定 "冒泡排序"

     選擇自 playyuer 的 Blog

    Java Code:
    class Class1
    {
     static void bubbleSort(int[] a)
     {
      for (int j = a.length - 1; j > 0; j--) // outer loop (backward)
       for (int i = 0; i < j; i++) // inner loop (forward)
        if (a[i] > a[i+1]) //Swap
        {
         a[i] = a[i] + a[i+1];
         a[i+1] = a[i] - a[i+1];
         a[i] = a[i] - a[i+1];
        }

     }
     public static void main(String[] args)
     {
      int[] a = new int[];
      //int[] a = new int[];
      bubbleSort(a);
      for (int i=0; i < a.length; i++)
      {
       System.out.println(a[i]);
      }
     }
    }

    C# Code:
    class Class1
    {
     static void BubbleSort(int[] a)
     {
      for (int j = a.Length - 1; j > 0; j--) // outer loop (backward)
       for (int i = 0; i < j; i++) // inner loop (forward)
        if (a[i] > a[i+1])
        {
         //a[i] = a[i] + a[i+1];
         //a[i+1] = a[i] - a[i+1];
         //a[i] = a[i] - a[i+1];
         Swap(ref a[i],ref a[i+1]);
        }
     }
     static void Swap(ref int x,ref int y)
     {
      x = x + y;
      y = x - y;
      x = x - y;
     }
     static void Main(string[] args)
     {
      int[] a = new int[];
      //int[] a = new int[];
      BubbleSort(a);
      for (int i=0; i < a.Length; i++)
      {
       System.Console.WriteLine(a[i]);
      }
      System.Console.ReadLine();
     }
    }

    http://dev.csdn.net/user/playyuer


    原文轉自:http://www.kjueaiud.com

    評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>