其他分享
首页 > 其他分享> > 冒泡排序

冒泡排序

作者:互联网

冒泡排序

冒泡排序动画
img

实现算法 (形式1)

//省略前面代码...
{
    int []num ={488, 848, 559, 15, 5, 11441}
            for (int i = 0; i < num.Length - 1; i++)
            {
                for (int j = 0; j < num.Length - 1 - i; j++)
                {
                    if (num[j] > num[j + 1])
                    {
                        int tem;
                        tem = num[j + 1];
                        num[j + 1] = num[j];
                        num[j] = tem;
                    }
                }
            }
}

变式

//省略前面代码...
{
    int []num ={488, 848, 559, 15, 5, 11441}
            for (int i = 0; i < num.Length - 1; i++)
            {
                for (int j = num.Length - 1- i; j >0 ; j--)
                {
                    if (num[j-1] > num[j])
                    {
                        int tem;
                        tem = num[j - 1];
                        num[j - 1] = num[j];
                        num[j] = tem;
                    }
                }
            }
}

标签:tem,int,冒泡排序,++,Length,num,变式
来源: https://www.cnblogs.com/moonsk/p/14966292.html