本帖最后由 耳东君 于 2014-3-31 16:17 编辑
class Demo
{
public static void BubbleSort(int [] arr)
{
for (int x = 0;x < arr.length-1;++x)
{
for (int y = 0;y < arr.length-x-1;++y)
{
if (arr[y] > arr[y+1])
{
int temp = arr[y];
arr[y] = arr[y+1];
arr[y+1] = temp;
}
}
}
}
public static void PrintArray(int [] arr)//遍历
{
System.out.print("[");
for (int x = 0;x < arr.length;++x)
{
if (x != arr.length-1);
System.out.print(arr[x]+",");
else
System.out.print(arr[x]+"]");
}
}
public static void main(String[] args)
{
int [] arr = {9,6,3,1,0,8,2};
BubbleSort(arr);
PrintArray(arr);
}
}
怎么会这样?
|
|