package com.shusheng.bubbleSort;
/**
* 冒泡排序
* @author Administrator
*
*/
public class BubbleSort {
public static void bubbleSort(int[] args){
int temp = 0;
for (int i = 0; i < args.length; i++) {//趟数
for (int j = 0; j <args.length-i-1; j++) {
if(args[j]>args[j+1]){//大于号表示当前面一个大于后面一个,就调换,说明排序后的顺序是从小到大的
temp = args[j];
args[j] = args[j+1];
args[j+1] = temp;
}
}
}
}
public static void main(String[] args) {
int[] args1 = {12,53,48,26,48,62,43,46};
bubbleSort(args1);
for (int i = 0; i < args1.length; i++) {
System.out.println(args1[i]);
}
}
}
冒泡排序--Java实现
最新推荐文章于 2024-03-20 23:41:10 发布