Description: public class BubbleSort{
static String printArray(int[] a){
String result=""
for(int i=0 i<a.length i++) result+=a[i]+" "
return result
}
static int[] bubbleSort(int[] a){
int t
for(int i=0 i<a.length i++)
{
for(int j=0 j<a.length-i-1 j++)
//升序排列用大于,降序排列用小于,此处为降序排列。
if(a[j]<a[j+1])
{t=a[j] a[j]=a[j+1] a[j+1]=t }
}
return a
}
public static void main(String args[])
{
int a[]={25,36,47,32,21,16}
System.out.println("排序前的数组\n"+printArray(a))
a=bubbleSort(a)
System.out.println("排序后的数组\n"+printArray(a))
}
}
To Search:
File list (Check if you may need any files):
java.doc