網站首頁 美容小常識 享受生活 東方時尚 識真假 高奢 資訊 遊戲攻略 搞笑段子
當前位置:品位站 > 享受生活 > 心理

sort是什麼排序|arrays

欄目: 心理 / 發佈於: / 人氣:1.21W
是什麼排序

是屬於升序的排序。

例如,一個整形的我數組,原來的順序是,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)

Tags:arrayssort