Results 1 to 25 of 25

Thread: VB - Quick Sort algorithm (very fast sorting algorithm)

Threaded View

  1. #19
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,309

    Re: VB - Quick Sort algorithm (very fast sorting algorithm)

    Don't get it personal CVMichalel but your code is fault. I check it without running, while I explain the code I post...

    Code:
        i = Int((max - min + 1) * Rnd + min)
        med_value = List(i)
         List(i) = List(min)    ' this is the beautiful point of the code.
    When we enter the outer Do Loop we have change the List(i) with List(min) so we have 2 times List(min) item.
    The Rnd function needed to us to pick any value not the value at the middle..There is always a best item to pick, and that item isn't in the middle. So with the rnd function...maybe we found it..In worse scenario we are the same as for the choice of middle...In that scenario all items are in the wrong position.
    The outer loop must find the place of chosen as "middle".
    In the first inner loop we setting the hi pointer to the item less than"middle".
    If we don't find any smaller then this is true hi<=lo and we put in List(lo) the "middle" item. So we found the right position...we perform a swap in three steps, two steps out of outer loop and one in the inner loop.

    Lets see what your routine do at the same situation.
    You pick the middle as actually middle (not a problem here), so we say that this item is the lowest from all other
    You skip the first inner loop, because you get an early false
    You going through all items in the second loop....

    if you don't find any item less that the middle....you get a BIG error because your pointer goes beyond limit...
    So you have to place as in code that i post (i can't remember which part is mine...but I remember that I do some changes), a line with a if clause like that
    If high < low Then Exit Do ' I change <= to < because you have this in the outer loop "Loop While Low <= High"

    So perhaps you correct your code, we have a High<Low condition.
    So the next "if" clause is skipped. Because you "Loop While Low <= High" your loop end without nothing doing
    next ...the First < High is false (high<low and first is low now)
    next ....the Low<Last is true (low is first now and last is the first high)...
    So you call exactly the same QuickSort C, Low, Last .FOREVER
    And for all your life...Your code is not working my friend...for 11 years.
    Have you ever put your code in an application??
    Last edited by georgekar; Aug 15th, 2014 at 02:53 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width