Results 1 to 3 of 3
  1. #1
    biglandphil is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default Hibbard's Shell Sort

    I have gotten down shell sort algorithms, but i just cant get Hibbard's increments. I get what they are, I just cant implement them into my basic shell sort. For other shell sorts, they go while gap>0, but with Hibbard it's counting up... when does it stop?? i figure if it goes while gap<array.length, the gap will eventually over shoot the end of the array?? please help!!

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    I just checked out the wikipedia page on it and from this pseudocode
    Java Code:
    input: an array a of length n with array elements numbered 0 to n − 1
    
    inc ← round(n/2)
    while inc > 0 do:
        for i = inc .. n − 1 do:
            temp ← a[i]
            j ← i
            while j ≥ inc and a[j − inc] > temp do:
                a[j] ← a[j − inc]
                j ← j − inc
            a[j] ← temp
        inc ← round(inc / 2.2)
    I'm assuming is the basis of what you're working with. Hibbard's sequence is 2x+1 all the way from 1 to array.length correct?

    If you're going while gap < array.length and incrementing up then it should stop before you reach an index out of bounds.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  3. #3
    biglandphil is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default

    yeah I tried doing it while gap<array.length but it would only work for very small array sizes (<1000) and would take very long. >1000 would not even work. I ended up just figuring out a high point to start at and working my down, and that worked fine. thanks for the reply.

Similar Threads

  1. Using Merge Sort to sort an ArrayList of Strings
    By coldfire in forum New To Java
    Replies: 3
    Last Post: 03-13-2009, 02:03 AM
  2. Bean Shell
    By Bisweswar in forum Advanced Java
    Replies: 2
    Last Post: 08-16-2008, 01:36 AM
  3. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 09:04 PM
  4. Shell Sort in Java
    By Java Tip in forum Algorithms
    Replies: 0
    Last Post: 04-15-2008, 08:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •