冒泡排序算法

package com.dragon.bean3;

import java.lang.reflect.Array;

public class Test1 {

/**
* 使用冒泡排序算法实现
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int str[] = new int[]{54,23,1,5,7,32,667};

System.out.println("未排序前:");
for (int i = 0; i < str.length; i++) {
System.out.print(str[i]+"\t");
}



for (int i = 0; i < str.length; i++) {
int temp;
for (int j = 0; j < i; j++) {

if(str[i]<str[j]){
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
System.out.println("");
System.out.println("排序后:");
for (int i = 0; i < str.length; i++) {
System.out.print(str[i]+"\t");
}
}

}

 
 

你可能感兴趣的:(冒泡排序)