阅读背景:

如何在Java中反转排序算法

来源:互联网 
public class Sort {

  public static void main(String[] args) {


    //fill the array with random numbers
    int[] unsorted = new int[100];
    for(int i = 0; i < 100; i++) {
      unsorted[i] = (int) (Math.random() * 100);
    }

    System.out.println("Here are the unsorted numbers:");
    for(int i = 0; i < 100; i++) {
      System.out.print(unsorted[i] + " ");
    }
    System.out.println();

    int[] sorted = new int[100];
    for(int i = 0; i < 100; i++) {
      int hi = -1;
      int hiIndex = -1;
      for(int j = 0; j < 100; j++) {
        if(unsorted[j] > hi) {
          hi = unsorted[j];
          hiIndex = j;
        }
      }
      sorted[i] = hi;
      unsorted[hiIndex] = -1;
    }
    System.out.println("Here are the sorted numbers: ");
    for(int i = 0; i < 100; i++) {
      System.out.print(sorted[i] + " ");
    }
    System.out.println();
  }
}
public class Sort {

  public static void main(



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: