Thursday 15 September 2011

java - Implementing BubbleSort at the end of QuickSort -


I get my bubbler and quoresort work at the end but how am I eager to change my code so that when I last 10 Elements are sorted in my quick shot, instead, I turn to BabelStore for fast overhead times.

  Fixed inte num_comps; Public static zero main (string [] args) {random random = new random (); // Maximum size of the array and the number of n sets int array_size = 32768; Int num_datasets = 10; // array set to maximum size [] vals = new int [array_size]; // Temporary for maximum size with periodic array [] tvals = new int [array_size]; // to keep the number of array operations int [] op_counts = new int [num_datasets]; Int [] op_counts2 = new int [num_datasets]; // array to capture the size of each array int [array] = new int [num_datasets]; Int i; Integer shape; (I = 0, size = 64; i & lt; num_datasets; i ++, size * = 2) array size [i] = size; For (int iter = 0; iter & lt; num_datasets; iter ++) {int curr_size = array size [iter]; // // with the random values ​​// fill array for 0-49 99 (i = 0; i & lt; curr_size; i ++) vals [i] = rnd.nextInt (4999); // Set the temporary array in the actual array for (i = 0; i & lt; curr_size; i ++) tvals [i] = vals [i]; // Bubble Sort Algorithm num_comps = 0; Bubble sort (TVL, curi_size); Op_counts [iter] = num_comps; // SYSTEM.out.println ("Number + compass" in "+ + +" is "+ num_comps"); Num_comps = 0; Quick Aart (TVL, curi_size); Op_counts2 [iter] = num_comps; } System.out.println ("n bubble sort order calculation quick sorted o"); For (int k = 0; k & lt; num_datasets; k ++) {System.out.println (array size [k] + "\ t \ t" + op_counts [k] + \ \ \ \ t \ t \ t "+ Op_counts2 [k]]); }} Fixed zero bubble sort (int call [], int curl_ shape) {int temp; For (int i = 0; i & lt; curr_size - 1; i ++) {for (int j = 0; j & lt; curr_size - i - 1; j ++) {// swap num_comps = num_comps + 1; If (Val [J + 1] and lieutenant vals [j]) {temp = vals [j]; Walls [J] = Wall [J + 1]; Walls [J + 1] = Temporary; }}}} Fixed zero instant sort (int call [], intra_isize) {quickSort_R (wal, 0, curu_size-1); } Fixed Zero Accelerated SRT_R (int vel [], int l, int r) {if (l & lt; r) {if ((r -1) == 1) // two elements - trivial sort {num_comps = num_comps + 1; If (Wal [L]> Wal [R] swap (WAL, L, R); Return; } // partition on pivot int s = partition (wal, l, r); // Recurse QuickSort_R (vals, l, s-1) at two split values; QuickSort_R (Wall, S + 1, R); }} Fixed Ent Partition (int call [], int l, int r) {int mid = (l + r) / 2; Int p = averageoffithry (wals, l, r); // Swap with first element swap (vals, l, p); Int pivot_val = vals [L]; Int i = l; Int j = r + 1; Do {num_comps = num_comps + 1; Taxes {i = i + 1; Num_comps = num_comps + 1; } While (vals [i] & lt; pivot_val); Do {j = j - 1; Num_comps = num_comps + 1; } While (wal [ja] gt; pwat_val); Swap (vals, i, j); } While (i & lt; j); Swap (vals, i, j); // Cancel the last swap swap (Wals, I, J); Put pivot on // j, return its correct position j; } StaticIndianAphththry (int val [], int first, it end) {int mid = (first + last) / 2; If (wal [first]   

}

The ejp is correct, but if you want For this, just modify your code like this:

  public static zero quickSort_R (integer vals [], int l, int r) {if (l    

No comments:

Post a Comment