关于冒泡排序
- Java code
public class BubbleSort { /** * @param args */ public static void main(String[] args) { int x[]= {10,1,2,3,5,80}; new BubbleSort().bubbleSortOther(x); for(int a:x){ System.out.println(a); } } public void bubbleSort(int x[]){ int temp; for(int i=0;i<x.length;i++){ for(int j=0;j<x.length-i-1;j++){ if(x[j]>x[j+1]){ temp = x[j]; x[j] = x[j+1]; x[j+1] = temp; } } } } public void bubbleSortOther(int x[]){ int temp; for(int i=0;i<x.length;i++){ for(int j=0;j<i;j++){ if(x[i]<x[j]){ temp = x[i]; x[i] = x[j]; x[j] = temp; } } } }}
我这下面写的bubbleSortOther(int x[]) 能算是冒泡排序不?
两个程序,结果都是一样的。
[解决办法]
不算。真要说的话这个更像选择排序。
[解决办法]
这个应该是选择排序