0

我希望能够对包含分数的 txt 文件进行冒泡排序。我已经能够对字母进行排序,但不能对整数进行排序。我确实有一个关于如何去做的想法。任何解决方案或输入将不胜感激。这是我已经拥有的冒泡排序代码。

public static void bubbleSort(int array[]) {
        boolean swapped = true;
        while (swapped) {
            swapped = false;
            for (int i = 0; i < array.length - 1; i++) {
                if (array[i] > array[i + 1]) {
                    swapped = true;
                    int temp = array[i];
                    array[i] = array[i + 1];
                    array[i + 1] = temp;
                }
            }
            for (int i = 0; i < array.length; i++) {
                System.out.print(array[i] + "\t");
            }
            System.out.println();
        }
}
4

1 回答 1

0

If there is no need for you to use Bubble Sort specifically, use the Arrays.sort() method for sorting the array.

It goes like this Arrays.sort(array);

于 2012-12-02T18:08:56.130 回答