排序 冒泡排序法

原文发布时间为:2009-03-06 —— 来源于本人的百度文章 [由搬家工具导入]

using System;//冒泡排序

namespace sorts
{
   public class Class3
    {
       public static void Main()
       {
           int[] a=new int[]{2,8,4,6,9,4};
           BubbleSort arr=new BubbleSort();
           arr.Sort(a);
           for(int i=0;i<a.Length;i++)
               Console.Write("{0} ",a[i]);
           Console.WriteLine();
           Console.ReadLine();
       }

    }
    public class BubbleSort
    {
        public void Sort(int[] arr)
        {
            for (int i = 0; i < arr.Length; i++)
                for (int j = 0; j < arr.Length-i- 1; j++)
                {
                    if (arr[j] > arr[j + 1])
                    {
                        int temp = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = temp;
                    }
                }
        }
    }
}

原文地址:https://www.cnblogs.com/handboy/p/7153252.html