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<=i; j++)
{
if (vArray[j] > vArray[j+1])
{
tmp=vArray[j] ;
vArray[j]=vArray[j+1] ;
vArray[j+1]=tmp ;
}
}
}
}
}
創作者介紹

My Life Going By My Style

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