冒泡排序

public class Bubble {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int [] num = {4,2,3,1,7,0,-1,2,3};
		Bubble b = new Bubble();
		System.out.println(Arrays.toString(b.bubble(num)));

	}
	/**
	 * bubble order
	 * @param num
	 * @return
	 */
	public int[] bubble(int [] num){
		int length = num.length;
		int n=0;
		while(n<length-1){
			for(int i=0;i<length-1-n;i++){
				if(num[i]>num[i+1]){
					int temp = num[i];
					num[i] = num[i+1];
					num[i+1] = temp;
				}
			}
			n++;
		}
		return num;
	}

}

 

你可能感兴趣的:(java)