package com.algorithm;
/**
* @Description 冒泡
* @author FuJianyong
* 2015-1-22上午09:58:39
*/
public class MaoPao {
public static void main(String[] args) {
int[] mao = {17,50,26,18,9,100,88};//静态分配数组初始数值
int temp = 0;
//外部重复履行遍历冒泡
for(int i=0;i<mao.length;i++) {
//内部重复履行相邻两个数组比拟,大的就冒泡
for(int j=0;j<mao.length-1;j++) {
//如果左侧的数组大于右侧的数组
if(mao[j]>mao[j+1]) {
temp = mao[j+1];//右侧的数组赋值给临时对象
mao[j+1] = mao[j];//左侧的数组赋值给右侧的数组
mao[j] = temp;//临时对象赋值给左侧的数组
}
}
}
for(int i=0;i<mao.length;i++) {
System.out.print(" "+mao[i]);
}
}
}
package com.algorithm;
/**
* @Description 冒泡
*