下面是我家了一点格式控制和输出语句后的结果,应该是你需要的吧!Data items in original order:
27 6 4 8 10 12 89 68 45 37
Data dealing order:
6 27 4 8 10 12 89 68 45 37
4 6 27 8 10 12 89 68 45 37
4 6 8 27 10 12 89 68 45 37
4 6 8 10 27 12 89 68 45 37
4 6 8 10 12 27 89 68 45 37
4 6 8 10 12 27 89 68 45 37
4 6 8 10 12 27 68 89 45 37
4 6 8 10 12 27 45 68 89 37
4 6 8 10 12 27 37 45 68 89
Data items in ascending order:
4 6 8 10 12 27 37 45 68 89

解决方案 »

  1.   

    运行没有问题,可能是你的配置问题, 以下是运行结果, 
    Data items in original order:
    27
    6
    4
    8
    10
    12
    89
    68
    45
    37
    6
    27
    4
    8
    10
    12
    89
    68
    45
    37
    4
    6
    27
    8
    10
    12
    89
    68
    45
    37
    4
    6
    8
    27
    10
    12
    89
    68
    45
    37
    4
    6
    8
    10
    27
    12
    89
    68
    45
    37
    4
    6
    8
    10
    12
    27
    89
    68
    45
    37
    4
    6
    8
    10
    12
    27
    89
    68
    45
    37
    4
    6
    8
    10
    12
    27
    68
    89
    45
    37
    4
    6
    8
    10
    12
    27
    45
    68
    89
    37
    4
    6
    8
    10
    12
    27
    37
    45
    68
    89
    Data items in ascending order:
    4
    6
    8
    10
    12
    27
    37
    45
    68
    89
      

  2.   

    只是我加的简单的注释,应该不难看懂.
    public class InsertSort
    {
    public static void main(String arg[])
    {
    //定义一个整型数组
    int a[]={27,6,4,8,10,12,89,68,45,37};
    System.out.println("Data items in original order:");
    //调用pringArray方法打印数组元素
    printArray(a);
    //调用sortInsert方法对数组进行排序,从小到大
    sortInsert(a);
    System.out.println("Data items in ascending order:");
    //显示排序后的数组元素
    printArray(a);
    }
    public static void sortInsert(int a[]){
    int hold,pass,i;
    //下面的算法是冒泡算法,用于排序
    for(pass=1;pass<a.length;pass++)
    {
    hold=a[pass];
    for(i=pass-1;i>=0;i--)
    if(a[i]>hold)
    a[i+1]=a[i];
    else
    break;
    a[i+1]=hold;
    printArray(a);
    }
    }
    public static void printArray(int b[])
    {
    for(int i=0;i<b.length;i++)
    System.out.println(""+b[i]);
    System.out.println("");
    }
    }