当前位置:柔美女性网 >

绿色生活 >心理 >

sort是什么排序 arrays

sort是什么排序 arrays

是什么排序

是属于升序的排序。

例如,一个整形的我数组,原来的顺序是,9、8、7、6、5、4、3、2、1。使用了()之后,获得的结果就变成了,1、2、3、4、5、6、7、8、9。

如果需要改变排序的话,变为降序的方式,需要改变排序方式,(要排序的内容,rseOrder())。

是对一个数组的所有元素进行排序,并且是按从小到大的顺序。

举例如下(点“+”可查看代码):

1 import ys

2

3 public class Main {

4 public static void main(String[] args) {

5

6 int[] a = {9, 8, 7, 2, 3, 4, 1, 0, 6, 5}

7 (a)

8 for(int i = 0 i < th i ++) {

9 t(a[i] + " ")

10 }

11 }

12

13 }

View Code

运行结果如下:

0 1 2 3 4 5 6 7 8 9

---------------------------------------------------------

2、(int[] a, int fromIndex, int toIndex)

这种形式是对数组部分排序,也就是对数组a的下标从fromIndex到toIndex-1的元素排序,注意:下标为toIndex的元素不参与排序哦!

举例如下(点“+”可查看代码):

1 import ys

2

3 public class Main {

4 public static void main(String[] args) {

5

6 int[] a = {9, 8, 7, 2, 3, 4, 1, 0, 6, 5}

7 (a, 0, 3)

8 for(int i = 0 i < th i ++) {

9 t(a[i] + " ")

10 }

11 }

12

13 }

View Code

运行结果如下:

7 8 9 2 3 4 1 0 6 5

上例只是把 9 8 7排列成了7 8 9

----------------------------------------------------------

3、public static <T> void sort(T[] a,int fromIndex, int toIndex, Comparator<? super T> c)

标签: arrayssort
  • 文章版权属于文章作者所有,转载请注明 https://rmnxw.com/lvse/xinli/5m956x.html