[英]Bubble Sort .txt file containing integers in java
I want to be able to bubble sort a txt file that contains scores. 我希望能够对包含分数的txt文件进行冒泡排序。 I have been able to sort alphabets but not integers. 我已经能够对字母排序,但不能对整数排序。 I done have an idea on how to go about it. 我确实对如何做到有一个想法。 Any solution or input would be highly appreciated. 任何解决方案或输入将不胜感激。 Here is the bubble sort code i have already. 这是我已经拥有的气泡排序代码。
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();
}
}
If there is no need for you to use Bubble Sort specifically, use the Arrays.sort()
method for sorting the array. 如果不需要专门使用冒泡排序,请使用Arrays.sort()
方法对数组进行排序。
It goes like this Arrays.sort(array);
就像这样Arrays.sort(array);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.