程序似乎也没错啊,为什么运行结果却不是从小到大

问题描述:

img


img

D:bianchenjavac 91.java
D:bianchenjava buble
 Original arry is:thisyy is a of a string iii
sorry array is:aa iii is of string thisyy
 D:bianchen

不是输出结果了吗,字符串的排序规则是根据字典排序的。不是字符串的长短比较。

你这个双循环排序用的是啥算法啊?

for(a=0;a<size-1;a++)
    for(b=0;b<size-i-1;b++)
    {
        if(num[b].compareTo(num[b+1]) > 0)
        {
            t = num[b];
            num[b]  = num[b+1];
            num[b+1] = t;
        }
    }