博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
冒泡排序demo
阅读量:3961 次
发布时间:2019-05-24

本文共 654 字,大约阅读时间需要 2 分钟。

package myFirstApp;

//冒泡排序demo

public class BubbleSort {

public static void main(String[] args) {	BubbleSort bs = new BubbleSort();	int l[] = new int[10];	for(int i=0;i<10;i++) {		l[i] = (int) (100 * Math.random());	}	System.out.print("list排序前为:");	bs.printList(l);		System.out.print("list排序后为:");			bs.printList(bs.sortNumber(l));}//打印list内容public void printList(int[] list) {	for (int x=0;x
lst[x]) { int t = lst[x-1]; lst[x-1] = lst[x]; lst[x] = t; complete = false; //排序一轮下来,是否仍有未排序的相邻数字 } } if(complete) { isSorted = true; } } return lst;}

}

输出结果是:

list排序前为:15 30 83 0 5 68 2 24 59 76
list排序后为:0 2 5 15 24 30 59 68 76 83

转载地址:http://urezi.baihongyu.com/

你可能感兴趣的文章
最长公共子序列
查看>>
计算几何
查看>>
求解方程
查看>>
太弱了。。水题
查看>>
位运算(含应用)
查看>>
野指针与空指针
查看>>
图文混排效果
查看>>
urllib2.urlopen超时问题
查看>>
魏兴国:深入浅出DDoS攻击防御
查看>>
使连续的参考文献能够中间用破折号连起来
查看>>
Discover Feature Engineering, How to Engineer Features and How to Get Good at It
查看>>
36辆车,6条跑道,无计时器,最少几次比赛可以选出前三
查看>>
matlab2012b与matlab7.1执行set(gca,'Yscale','log')之后画到的直方图结果居然不同
查看>>
回文题
查看>>
AJAX应用之注册用户即时检测
查看>>
File 类小结
查看>>
java除去字符串空格
查看>>
jsp 2.0标记文件
查看>>
Hibernate中Criteria的完整用法
查看>>
sql jsp
查看>>