Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void shellSortK(){
- // Figure K \\
- int k = 1;
- while (k < currentSize)
- k = k*2; // keep doubling until we exceed currentSize
- //k = k/2; // take one step back down. This is the starting k
- //while loop to trigger recursive insertions
- while (k >= 2){
- k = k/2; //stepdown k
- // System.out.println("ssK:"+k); //debug line
- shellSortS(k);
- }//end while
- // insertionSort(); //plain insertion sort,
- isSorted = true;
- }//end shellsort Method
- public void shellSortS(int step){
- int overbite = currentSize % step; // number of loops with more entries
- int size = (currentSize / step); // number of entries
- for (int start = 0; start < step; start++){
- // System.out.println("ssS:"+size); //debug line
- if (size > 1)
- shellSortR(start, step, size);
- if (start == overbite && overbite != 0)
- size--;
- if (size == 1)
- break;
- }//end for
- }//end shellSortS
- public void shellSortR (int start ,int step, int size){ // RECURSION
- // if (size == 1)
- // System.out.println("Bottom of K="+step+" I="+start); //debug line
- if (size > 1){
- // System.out.print("."); //debug line
- shellSortR(start, step, size-1); //send down recursive call
- }//end if (size > 1)
- // sort section
- // printArray();//debug line
- // run left to right
- for (int i = 0; i < size; i++){
- int l = i*step+start; // check contents of L = i*step+start
- int r = l + step; // compare to R = (i+1)*step+start
- if (r >= currentSize) // if L is bigger, swap
- break;
- //System.out.println("A["+l+"]="+A[l]+" | A["+r+"]="+A[r]); //debug line
- if (A[l] > A[r]){
- System.out.println("A["+l+"]="+A[l]+" | A["+r+"]="+A[r]); //debug line
- swap( A, l, r);
- break;
- }//end if
- } //end for
- printArray();//debug line
- } // end method ShellSortR
Add Comment
Please, Sign In to add comment