Esempio n. 1
0
  public static void main(String[] args) {
    ArrayList<Long> estimatedBubbleTimeArray = new ArrayList<>();
    ArrayList<Long> estimatedBubbleTimeArrayList = new ArrayList<>();
    long estimatedInsertionTime = 0;
    long estimatedSelectionTime = 0;

    // Base for measuring time in sorting with Strings
    for (int i = 0; i < 10; i++) {
      String[] stringArrayBubble = {
        "Erna", "Elly", "Laurits", "Bertha", "Christian", "August", "Marius", "John", "Tove", "Poul"
      };

      long startTimeArray = System.nanoTime();
      Sorting.<String>bubbleSort(stringArrayBubble);
      estimatedBubbleTimeArray.add(System.nanoTime() - startTimeArray);

      ArrayList<String> stringArrayListBubble = new ArrayList<>();
      stringArrayListBubble.add("Erna");
      stringArrayListBubble.add("Elly");
      stringArrayListBubble.add("Laurits");
      stringArrayListBubble.add("Bertha");
      stringArrayListBubble.add("Christian");
      stringArrayListBubble.add("August");
      stringArrayListBubble.add("Marius");
      stringArrayListBubble.add("John");
      stringArrayListBubble.add("Tove");
      stringArrayListBubble.add("Poul");

      long startTimeArrayList = System.nanoTime();
      Sorting.<String>bubbleSort(stringArrayListBubble);
      estimatedBubbleTimeArrayList.add(System.nanoTime() - startTimeArrayList);
    }
    System.out.println(estimatedBubbleTimeArray);
    System.out.println(estimatedBubbleTimeArrayList);

    String[] stringArrayBubble = {
      "Mark",
      "Nikolaj",
      "Henrik",
      "Tommy",
      "Jesper",
      "Jonas",
      "Margrethe",
      "Liv",
      "Birgitte",
      "Anders"
    };
    long startTimeArrayList = System.nanoTime();
    Sorting.<String>bubbleSort(stringArrayBubble);
    System.out.println(System.nanoTime() - startTimeArrayList);
  }
Esempio n. 2
0
  public void testBubbleSort() {
    long before, after;
    System.out.println("Testing bubble sort.");
    for (int i = 0; i < 5; i++) {
      before = System.currentTimeMillis();
      sort.bubbleSort(lists[i]);
      after = System.currentTimeMillis();

      System.out.println(after - before);
    }
  }
  public static void main(String[] args) {
    Sorting sorting = new Sorting();
    int[] intArray = {3, 6, 7, 9, 1, 2, 4, 5, 8, 0};
    System.out.print("Array Elements before sorting : ");
    sorting.printArrayElements(intArray);

    // System.out.println("Array Elements after SELECTION sorting : ");
    // sorting.selectionSort(intArray);

    System.out.println("Array Elements after BUBBLE sorting : ");
    sorting.bubbleSort(intArray);

    // System.out.println("Array Elements after INSERTION sorting : ");
    // sorting.insertionSort(intArray);
  }
Esempio n. 4
0
 private void btnbubActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnbubActionPerformed
   disbutton();
   list.clear();
   start = System.currentTimeMillis();
   bubbleSort(num);
   end = System.currentTimeMillis();
   time = (end - start);
   if (time >= 1000) {
     time = time / 1000;
     lblbub.setText("" + time + " Seconds");
   } else {
     lblbub.setText("" + time + " Milliseconds");
   }
   for (int x = 1; x <= amnt; x++) {
     list.addElement(num[x]);
   }
 } // GEN-LAST:event_btnbubActionPerformed