/* 冒泡排序算法 */

类别:Java 点击:0 评论:0 推荐:

public class Test
{
    public static void main(String args[])
    {
        int[] m =
        { 2, 8, 43, 3, 33, 1, 35, 34, 6, 9 };
        int[] n = sort(m);
        for (int i = 0; i < m.length; i++)
        {
            System.out.println(n[i] + "\n");
        }

    }

    /* 冒泡排序算法 */
    public static int[] sort(int[] m)
    {
        int intLenth = m.length;
        /*执行intLenth次*/
        for (int i = 0; i < intLenth; i++)
        {
            /*每执行一次,将最小的数排在后面*/
            for (int j = 0; j < intLenth - i - 1; j++)
            {
                int a = m[j];
                int b = m[j + 1];
                if (a < b)
                {
                    m[j] = b;
                    m[j + 1] = a;
                }
            }
        }
        return m;

    }
}

本文地址:http://com.8s8s.com/it/it9979.htm