`
狂奔的蜗牛zyx
  • 浏览: 18824 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

简单的冒泡排序

阅读更多
public class Maopao {
	public static void main(String[] args) {
		int[] a={1,5,8,10,0,-1,6,15,5};
		for(int i=0;i<a.length;i++){
			for (int j = 0; j < a.length-i-1; j++) {
				if(a[j]<a[j+1]){
				int temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
				}
			}
		}
		for (int k : a) {
			System.out.println(k);
		}
	}
}


升序口诀:N数数组冒泡序,两两相比小前去,内层大标减去i(-1-i),外层要用N-1。
升序和降序只需改变 if(a[j]>a[j+1])条件即可。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics