冒泡排序:

namespace BubbleSorter
{
    public class BubbleSorter
    {
        static void Main(string[] args)
        {
            int[] arr = new int[] {50,6,45,94,78};
            BubbleSorter sh = new BubbleSorter();
            sh.Sort(arr);
            for (int m = 0; m < arr.Length; m++)
            Console.Write(" {0} ", arr[m]);
            Console.WriteLine();
            Console.ReadLine();
        }
        public void Sort(int[] list)
        {
            int i, j, temp;
            j = 1;
            for (i = 0; i < list.Length - j; i++)
            {
                if (list[i] > list[i + 1])
                {
                    temp = list[i];
                    list[i] = list[i + 1];
                    list[i + 1] = temp;
                }
            }
            j++;
        }
    }
}
posted on 2021-03-31 11:32  羲和i  阅读(48)  评论(0)    收藏  举报