选择排序,冒泡排序,插入排序,合并排序,桶排序,基数排序,希尔排序,折半插入排序
冒泡排序:
class MaoPao
{
public static void main(String[] args)
{
int[] arr={102,512,8,89,7,4,12,45,24};
for (int x=0;x<arr.length-1; x++)
{
for (int y=0;y<arr.length-1-x ;y++ )
{
if (arr[y]>arr[y+1])
{
int temp=arr[y];
arr[y]=arr[y+1];
arr[y+1]=temp;
}
}
}
for (int x=0;x<arr.length ;x++ )
{
if (x<arr.length-1)
System.out.print(arr[x]+",");
else
System.out.print(arr[x]);
}
}
}
|
|