码迷,mamicode.com
首页 > 编程语言 > 详细

冒泡排序

时间:2015-04-17 23:46:52      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

(java版)

 

public class bubbleSort {

static void BubbleSort(int l[]){
int i,j;
boolean exchange = false;
int swap;
for(i = 0; i<l.length-1; i++){
for(j = l.length-1; j>i; j--){
if(l[j] < l[j-1]){
swap = l[j-1];
l[j-1] = l[j];
l[j] = swap;
exchange = true;
}
if(!exchange)
return;
}
}
}

public static void main(String[] args) {
int[] a = {0,2,5,43,32,65,43,21,87,1};
BubbleSort(a);
for(int i = 0; i<a.length; i++)
System.out.print(a[i]+" ");
}
}

冒泡排序

标签:

原文地址:http://www.cnblogs.com/tangtang-123/p/4436040.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!