Results 1 to 5 of 5

Thread: Quick Sort

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    3

    Quick Sort

    Can someone explain why my lines don't redraw properly in my quicksort tutorial?

    Here's the code...

    Sub Quicksort(List() As Integer, min As Integer, max As Integer)
    ' If the list has no more than 1 element, it's sorted.
    If min >= max Then Exit Sub

    ' Pick a dividing item.
    i = Int((max - min + 1) * Rnd + min)
    med_value = List(i)

    ' Swap it to the front so we can find it easily.
    List(i) = List(min)

    ' Move the items smaller than this into the left
    ' half of the list. Move the others into the right.
    lo = min
    hi = max
    Do
    ' Look down from hi for a value < med_value.
    Do While List(hi) >= med_value
    hi = hi - 1
    If hi <= lo Then Exit Do
    Loop

    If hi <= lo Then
    List(lo) = med_value
    Exit Do
    End If

    ' Swap the lo and hi values.
    Form1.Line (2400 + lo * 50, 0)-(2400 + lo * 50, List(lo)), vbBlue
    Form1.Line (2400 + hi * 50, 0)-(2400 + hi * 50, List(hi)), vbBlue
    'delay
    Sleep (100)
    Form1.Line (2400 + lo * 50, 0)-(2400 + lo * 50, List(lo)), vbBlack
    Form1.Line (2400 + hi * 50, 0)-(2400 + hi * 50, List(hi)), vbBlack
    List(lo) = List(hi)
    Sleep (100)
    Form1.Line (2400 + lo * 50, 0)-(2400 + lo * 50, List(lo)), vbGreen
    Form1.Line (2400 + hi * 50, 0)-(2400 + hi * 50, List(hi)), vbGreen

    ' Look up from lo for a value >= med_value.
    lo = lo + 1
    Do While List(lo) < med_value
    lo = lo + 1
    If lo >= hi Then Exit Do
    Loop
    If lo >= hi Then
    lo = hi
    List(hi) = med_value
    Exit Do
    End If

    ' Swap the lo and hi values.
    Form1.Line (2400 + lo * 50, 0)-(2400 + lo * 50, List(lo)), vbBlue
    Form1.Line (2400 + hi * 50, 0)-(2400 + hi * 50, List(hi)), vbBlue
    'delay
    Sleep (100)
    Form1.Line (2400 + lo * 50, 0)-(2400 + lo * 50, List(lo)), vbBlack
    Form1.Line (2400 + hi * 50, 0)-(2400 + hi * 50, List(hi)), vbBlack
    List(hi) = List(lo)
    Sleep (100)
    Form1.Line (2400 + lo * 50, 0)-(2400 + lo * 50, List(lo)), vbGreen
    Form1.Line (2400 + hi * 50, 0)-(2400 + hi * 50, List(hi)), vbGreen

    Loop
    ' Sort the two sublists
    Quicksort List(), min, lo - 1
    Quicksort List(), lo + 1, max


    End Sub


    Thank You

  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Chuck in a Me.Refresh after the drawing code.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    3

    didn't work

    thanx anyways but it didn't work.. this thing is so frustrating

    thanx

  4. #4
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    At the end of the loop, just before Loop statement, add:

    Me.Enabled = False
    DoEvents
    Me.Refresh
    Me.Enabled = True

    Also add the above 4 lines after every "sleep" command.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    3
    The code that u gave me makes perfect sense but unfortunately it clears the original lines.. if u would like me to send u a copy of the program email me...

    [email protected]

    thanx

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