Example #1
0
  private void jButton2ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton2ActionPerformed

    this.dispose();
    SelectionSort ss = new SelectionSort();
    ss.setVisible(true);
  } // GEN-LAST:event_jButton2ActionPerformed
Example #2
0
  public static void run(int[] array) {
    if (array == null || array.length < 2) return;

    SelectionSort ss = new SelectionSort();
    ss.array = array;
    ss.sort();
  }
  public static void main(String[] args) {
    System.out.println("Application starts...");

    int[] arr = {3, 34, 200, 3, 5, 3, 1, 34, 5, 34};
    SelectionSort ss = new SelectionSort();
    arr = ss.sortArrUsingSelection(arr);

    for (int i = 0; i < arr.length; i++) {
      System.out.print(arr[i] + "-> ");
    }
  }
Example #4
0
  public static void main(String[] args) {
    //  create object to perform selection sort
    SelectionSort sortArray = new SelectionSort(10);

    System.out.println("Unsorted array:");
    System.out.println(sortArray + "\n"); //  print unsorted array.

    sortArray.sort();

    System.out.println("Sorted array:");
    System.out.println(sortArray);
  }
 /** Test InsertionIndex.sort() on given array */
 public void testSelectionSort(int[] arr) {
   System.out.println(String.format("Selection sort on input: %s", Arrays.toString(arr)));
   SelectionSort.sort(arr);
   System.out.println(String.format("Result: %s", Arrays.toString(arr)));
   System.out.println();
   assertTrue(TestUtil.isArraySorted(arr));
 }
  @Test
  public void testRecursiveSort4() throws Exception {

    int a[] = {1, 5, 2, 7, 3};
    selectionSort.recursiveSort(a);
    assertEquals("[1,2,3,5,7]", ArrayHelper.arrayAsString(a));
  }
  @Test
  public void testRecursiveSort3() throws Exception {

    int a[] = new int[5];
    selectionSort.recursiveSort(a);
    assertEquals("[0,0,0,0,0]", ArrayHelper.arrayAsString(a));
  }
  @Test
  public void testRecursiveSort1() throws Exception {

    int a[] = null;
    selectionSort.recursiveSort(a);
    assertNull(a);
  }
Example #9
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    SelectionSort sorter = new SelectionSortImpl();
    long gesammtvergleiche = 0;
    int gesammtmillisec = 0;
    int n = 10;
    int durchlaufanz = 100;
    Random rand = new Random();
    for (int durchlaeufe = 0; durchlaeufe < durchlaufanz; durchlaeufe++) {
      int[] tests = new int[n];
      for (int i = 0; i < tests.length; i++) {
        tests[i] = rand.nextInt();
      }
      long time1 = System.currentTimeMillis();
      tests = sorter.sort(tests);
      long time2 = System.currentTimeMillis() - time1;

      gesammtvergleiche += sorter.getAnzVergleiche();
      gesammtmillisec += time2;
    }
    System.out.println("Gesammt: " + gesammtmillisec / durchlaufanz + " ms");
    System.out.println(gesammtvergleiche / durchlaufanz + " Vergleiche");
  }
Example #10
0
  public static void main(String[] args) {
    // Array length
    int length = 20000;
    // Random number range
    int range = 200;
    // Print results
    boolean print = false;
    // For measuring performance
    long startTime, endTime;

    int[] unsortedArray = new int[length];

    // Array of randomly generated numbers
    Random generator = new Random();
    for (int i = 0; i < unsortedArray.length; i++) {
      unsortedArray[i] = generator.nextInt(range);
    }

    // BubbleSort run
    startTime = System.nanoTime();
    int[] bubbleSortedArray = BubbleSort.sort(unsortedArray);
    endTime = System.nanoTime();
    System.out.println("BubbleSort " + (endTime - startTime));

    // SelectionSort run
    startTime = System.nanoTime();
    int[] selectionSortedArray = SelectionSort.sort(unsortedArray);
    endTime = System.nanoTime();
    System.out.println("SelectionSort " + (endTime - startTime));

    // HeapSort run
    startTime = System.nanoTime();
    int[] heapSortedArray = HeapSort.sort(unsortedArray);
    endTime = System.nanoTime();
    System.out.println("HeapSort " + (endTime - startTime));

    // Print the arrays
    if (print) {
      Helper.printArray(unsortedArray);
      Helper.printArray(bubbleSortedArray);
      Helper.printArray(heapSortedArray);
      Helper.printArray(selectionSortedArray);
    }
  }
Example #11
0
 @Test
 public void testSort() {
   SelectionSort m = new SelectionSort();
   System.out.println("\nclass:" + m.getClass().getName());
   runTest(m);
 }
Example #12
0
 @Test
 public void selectionSortArray() throws Exception {
   int[] actual = SelectionSort.selectionSortArray(arr);
   assertArrayEquals(expected, actual);
 }
Example #13
0
 @Test
 public void testSelectionSort() {
   List<Integer> list = getRandomUnsortedList();
   testSort(list, SelectionSort.sort(list));
 }
Example #14
0
 public static void main(String[] args) {
   int[] intArrayValues = {90, 2, 89, 1, 76, 63};
   ArrayDisplay.arrayValueDisplay(SelectionSort.selectionSort(intArrayValues));
 }