java--冒泡排序

package com.test;

public class test {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	int[] arr= {22,33,44,55,66};
	print(arr);
	
}
public static void bub(int[] arr) {
	for (int i=0;i<arr.length-1; i++ ) {
		for (int j=0;j<arr.length-1-i; j++ ) {
			if(arr[j]> arr[j+1]) {
				int tmp =arr[j];
				arr[j]=arr[j+1];
				arr[j+1]=tmp;
			}
		}
	}
}
public static void print (int[] arr) {
	for (int i=0;i<arr.length; i++ ) {
	System.out.println(arr[i]);
	}
}

}

posted @ 2020-05-26 08:49  雨曼晴川  阅读(79)  评论(0编辑  收藏  举报