本帖最后由 陈泽鑫 于 2012-12-8 23:22 编辑
自己写的一个冒泡排序
class bubbleSort
{
public static void main(String[] args)
{
int[] arr = {25,485,2185,1,21,3,0,15,15,545,4,312};
System.out.print("原: ");
for (int x = 0;x < arr.length ;x++ )
{
System.out.print(arr[x]+",");
}
System.out.println();
for (int x = arr.length-1 ;x > 0 ;x-- )
{
int index = x,temp = arr[x];
for (int y = 0; y < x ;y++ )
{
if(temp < arr[y])
{
temp = arr[y];
index = y;
}
}
temp = arr[x];
arr[x] = arr[index];
arr[index]=temp;
}
System.out.print("改: ");
for (int x = 0;x < arr.length ;x++ )
{
System.out.print(arr[x]+",");
}
System.out.println();
}
}
|