标签:
package maopao;
public class MaoPaoPaiXu {
/**
* 方法一:
* @param array
* @return
*/
public static int[] getSort(int[] array)
{
int length = array.length;
for (int i = 0; i < length; i++)
{
for (int j = length-i- 1; j > i; j--)
{
if (array[j] < array[j - 1])
{
int temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
}
return array;
}
public static void main(String[] args) {
int[] arr={5,6,1,9,3,10,2,8,7,4};
/**
* 方法二:
*/
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j <arr.length-1 ; j++) {
if(arr[j]>arr[j+1]){
int temp;
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+",");
}
System.out.println("\n***************************************");
/**
* 方法一:
*/
int[] arr1=getSort(arr);
for (int i = 0; i < arr1.length; i++) {
System.out.print(arr1[i]+",");
}
}
}
标签:
原文地址:http://www.cnblogs.com/mycainiao/p/5499380.html