package com.bjpowernode;
import java.util.Arrays;
public class TestSort {
public static void main(String[] args) {
int arr[]={8,1,6,3,2,4,5,1,7};
int len=arr.length;
int [] sortVal=testSort(arr, len);
System.out.println("Arrays.toString(sortVal):"+ Arrays.toString(sortVal));
}
public static int [] testSort(int arr [],int n){
int temp;
Boolean flag=false;
System.out.println("arr[] 的长度:"+n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n-i-1; j++) {
if(arr[j] > arr[j+1]){
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
flag=true;
}
}
if(!flag) break;
}
return arr;
}
}
--------------------------------------------------------
arr[] 的长度:9
Arrays.toString(sortVal):[1, 1, 2, 3, 4, 5, 6, 7, 8]
注意:
返回类型为int 数组 :
public static int [] testSort(int arr [],int n)
输出int 数组:
Arrays.toString(list);
原文:https://www.cnblogs.com/2016-cxp/p/11110629.html