package com.algorithm;
/**
* describe: 冒泡排序(排序结果从小到大)
* create on: 2011-05-25
* @author sylor.liu
* @version 1.0
* @since jdk1.6
*/
public class Bubblesort {
// 对数组a内的值,进行冒泡排序
public static void sort(int a[]){
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+1];
a[j+1] = a[j];
a[j] = temp;
}
}
}
}
// 排印排序后的结果
public static void printBubbleSortResult(int a[]){
for(int i = 0; i < a.length; i++){
System.out.print(a[i] + ", ");
}
System.out.println();
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = {2,4,23,1,45,6,33};
Bubblesort.sort(a);
Bubblesort.printBubbleSortResult(a);
}
}