冒泡排序

1.冒泡排序

public static void BubbleSort(int[] arr)
        {
            int i = arr.Length - 1;
            int last = 0;

            while (i > 1)
            {
                last = 0;
                for (int j = 0; j < i; j++)
                {
                    if (arr[j] > arr[j + 1])
                    {
                        int temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                        last = j;
                    }                    
                }
                i = last;
            }
        }

 

posted @ 2018-05-02 22:35  vvf  阅读(99)  评论(0编辑  收藏  举报