class test15
{
public static void main(String[] args)
{
int[] myArray=new int[] {31, 12, 16, 10, 78} ;
System.out.print(" 排序前->");
for (int i=0; i System.out.print(" " + myArray[i]);
BubbleSort(myArray) ;
System.out.println();
System.out.print(" 排序後->");
for (int i=0; i System.out.print(" " + myArray[i]);
}
static void BubbleSort(int[] vArray)
{
int tmp=0 ;
for (int i=vArray.length-2 ; i>=0 ; i--)
{
for (int j=0 ; j {
if (vArray[j] > vArray[j+1])
{
tmp=vArray[j] ;
vArray[j]=vArray[j+1] ;
vArray[j+1]=tmp ;
}
}
}
}
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Neo Chao 的頭像
    Neo Chao

    My Life Goes By My Style

    Neo Chao 發表在 痞客邦 留言(0) 人氣()