Guest User

Untitled

a guest
Jan 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1.     public void shellSortK(){
  2.         // Figure K \\
  3.         int k = 1;
  4.         while (k < currentSize)
  5.             k = k*2;    // keep doubling until we exceed currentSize
  6.         //k = k/2; // take one step back down. This is the starting k
  7.  
  8.         //while loop to trigger recursive insertions
  9.         while (k >= 2){
  10.             k = k/2; //stepdown k
  11.   //          System.out.println("ssK:"+k); //debug line
  12.             shellSortS(k);
  13.         }//end while
  14.        // insertionSort(); //plain insertion sort,
  15.         isSorted = true;
  16.     }//end shellsort Method
  17.     public void shellSortS(int step){
  18.         int overbite = currentSize % step; // number of loops with more entries
  19.         int size = (currentSize / step); // number of entries
  20.         for (int start = 0; start < step; start++){
  21.         //    System.out.println("ssS:"+size); //debug line
  22.             if (size > 1)
  23.                 shellSortR(start, step, size);
  24.             if (start == overbite && overbite != 0)
  25.                 size--;
  26.             if (size == 1)
  27.                 break;
  28.         }//end for
  29.     }//end shellSortS
  30.     public void shellSortR (int start ,int step, int size){ // RECURSION
  31.      //   if (size == 1)
  32.     //         System.out.println("Bottom of K="+step+" I="+start); //debug line
  33.         if (size > 1){
  34.   //          System.out.print("."); //debug line
  35.             shellSortR(start, step, size-1); //send down recursive call
  36.         }//end if (size > 1)
  37.  
  38.         // sort section
  39.        // printArray();//debug line
  40.       // run left to right
  41.         for (int i = 0; i < size; i++){
  42.             int l = i*step+start;         // check contents of L = i*step+start
  43.             int r = l + step;            //  compare to R = (i+1)*step+start
  44.             if (r >= currentSize)       //   if L is bigger, swap
  45.                 break;
  46.             //System.out.println("A["+l+"]="+A[l]+" | A["+r+"]="+A[r]); //debug line
  47.             if (A[l] > A[r]){
  48.                 System.out.println("A["+l+"]="+A[l]+" | A["+r+"]="+A[r]); //debug line
  49.                 swap( A, l, r);
  50.                 break;
  51.             }//end if
  52.         }   //end for
  53.         printArray();//debug line
  54.     }     //  end method ShellSortR
Add Comment
Please, Sign In to add comment