コード例 #1
0
ファイル: QuickSort.java プロジェクト: kentoa/test
  public static void main(String[] args) {
    QuickSort process = new QuickSort();
    process.input(args[0]);

    int[] array = process.toArray(list);

    long start = System.currentTimeMillis();

    process.quickSort(array, 0, array.length - 1);

    long end = System.currentTimeMillis();
    System.out.println("Time:" + (end - start) / 1000000f + "ms");

    process.print(array);
  }
コード例 #2
0
 /**
  * Writes header information and calls necessary procedures.
  *
  * @param args Array of command line parameters.
  */
 public static void main(String[] args) {
   String asuFile = args[0];
   QuickSort demo = new QuickSort(asuFile);
   Random r = new Random();
   int num = r.nextInt(11) + 10;
   int[] array = new int[num];
   // Forgive me God, this is an ugly way to guarantee no repeats, but the
   // the array is small and computers are fast!
   for (int i = 0; i < array.length; i++) {
     boolean repeat;
     do {
       array[i] = r.nextInt(99) + 1;
       repeat = false;
       for (int j = 0; j < i; j++) {
         repeat = repeat || (array[j] == array[i]);
       }
     } while (repeat);
     System.out.println("" + array[i]);
   }
   int visArrayLen = array.length + 2;
   int lastNum = array.length - 1;
   demo.out.println("%Animal 2");
   demo.out.println("{");
   demo.out.print("array \"qarray\" (100,10) color black fillColor white");
   demo.out.print(" elementColor black elemHighlight red cellHighlight yellow");
   demo.out.print(" vertical length ");
   demo.out.print("" + visArrayLen + " ");
   for (int j = 0; j < array.length; j++) demo.out.print("\"" + array[j] + "\"");
   demo.out.println("\"Pivot\"\"X\"");
   demo.out.println("highlightArrayCell on \"qarray\" position " + array.length);
   demo.out.println("arrayMarker \"lo\" on \"qarray\" atIndex 0 label \"lo\"");
   demo.out.print("arrayMarker \"hi\" on \"qarray\" atIndex ");
   demo.out.println("" + lastNum + " label \"hi\"");
   demo.out.println("}");
   demo.out.println("{");
   demo.sort(array, 0, array.length - 1);
   demo.out.println("}");
   demo.questions.animalWriteQuestionsAtEOSF();
   demo.out.close();
 }