三大基础算法之冒泡排序

public static void BubbleSort(this int[] array)
{
            //82,22,33,12,33,44,22,34,56
            //22,82,33,12,33,44,22,34,56
            //22,33,82,12,33,44,22,34,56
            //22,33,12,82,33,44,22,34,56
            //22,33,12,33,82,44,22,34,56
            //22,33,12,33,44,82,22,34,56
            //22,33,12,33,44,22,82,34,56
            //22,33,12,33,44,22,82,34,56
            //22,33,12,33,44,22,34,82,56
       
            int temp = 0;
            for (int i = 0; i < array.Length; i++)
            {
                for (int j = 0; j < array.Length - 1 - i; j++)
                {
                    if (array[j] > array[j + 1])
                    {
                        temp = array[j];
                        array[j] = array[j+1];
                        array[j+1] = temp;
                    }
                    array.Show();
                }
                
            }
}

  

posted @ 2022-07-13 16:03  法外狂徒派大星  阅读(14)  评论(0)    收藏  举报