JAVA常见算法题(三十一)---冒泡排序
2017-07-08 12:10
232 查看
package com.jege.spring.boot.hello.world; /** * java算法之冒泡排序<br> * 将数组按照从大到小的顺序排列<br> * * * @author Administrator * */ public class BubbleSort{ public static void main(String[] args){ int score[] = {67, 69, 75, 87, 89, 90, 99, 100}; for (int i = 0; i < score.length -1; i++){ //最多做n-1趟排序 for(int j = 0 ;j < score.length - i - 1; j++){ //对当前无序区间score[0......length-i-1]进行排序(j的范围很关键,这个范围是在逐步缩小的) if(score[j] < score[j + 1]){ //把小的值交换到后面 int temp = score[j]; score[j] = score[j + 1]; score[j + 1] = temp; } } System.out.print("第" + (i + 1) + "次排序结果:"); for(int a = 0; a < score.length; a++){ System.out.print(score[a] + "\t"); } System.out.println(""); } System.out.print("最终排序结果:"); for(int a = 0; a < score.length; a++){ System.out.print(score[a] + "\t"); } } }
运行结果:
相关文章推荐
- 几种常见排序算法之Java实现(插入排序、希尔排序、冒泡排序、快速排序、选择排序、归并排序)
- Java常见排序算法之冒泡排序
- 常见算法学习及其Java实现--插入排序算法
- 常见算法学习及其Java实现--冒泡算法实现
- Java经典算法:冒泡排序
- 大学常见算法的java实现及思考-打印帕斯卡三角形(杨辉三角)
- 大学常见算法的java实现及思考-汉诺塔问题
- 常见(经典)程序练习题(含算法,c答案,java答案)
- 用Java写算法之一:冒泡排序
- 【算法】【JAVA】冒泡排序
- java 算法基础之六插入排序与冒泡排序
- 黑马程序员--02.Java语言基础--04.【数组中常见的算法】
- java常见算法
- java常见的开源算法支持以及java默认支持的provider
- 用JAVA实现排序算法之一:冒泡排序
- Java算法排序之--冒泡排序、快速排序
- 常见算法学习及其Java实现--有序区和无序区的冒泡算法实现
- 几种常见算法的JAVA实现
- java基础知识之 算法 【冒泡排序】【快速排序】
- Java原来如此-几种常见的排序--冒泡排序(Bubble Sort)