冒泡排序java的实现
public class Sort {
??
?public int[] bubbleSort(int[] initialArray)
?{
??int initialArrayLength = initialArray.length;????
??int minv = 0;?//定义最小值?
??int i,j;
??for(i=0; i<initialArrayLength; i++)
??{
???minv = initialArray[0];
???for(j = 1; j < initialArrayLength - i; j++)
???{
????if(initialArray[j] < minv)
????{
?????minv = initialArray[j];
????}else
????{
?????initialArray[j-1] = initialArray[j];
?????initialArray[j] = minv;
????}
???}
??}?
??return initialArray;
?}
?
?public static void main(String args[])
?{
??int[] test = {3,4,3,3,5,-7,7};
??Sort sort = new Sort();
??test = sort.bubbleSort(test);
??for(int i=0; i<test.length; i++)
??{
???System.out.print(test[i]+",");
??}
?}
}
?
打印结果:7,5,4,3,3,3,-7,
?