您需要两个循环来实现Bubble Sort。
样例代码:
public static void bubbleSort(int[] numArray) { int n = numArray.length; int temp = 0; for (int i = 0; i < n; i++) { for (int j = 1; j < (n - i); j++) { if (numArray[j - 1] > numArray[j]) { temp = numArray[j - 1]; numArray[j - 1] = numArray[j]; numArray[j] = temp; } } }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)