Results 1 to 9 of 9

Thread: bubble sorting a dictionary object ?

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    37

    bubble sorting a dictionary object ?

    I have a dictionary consisting of an array of words as the keys and the number of occurences of each word as the items. I want sort this dictionary by number of occurences of each key, in descending order, so that I may be able to take the top 20 most used words. I want to use a bubble sort but I seem to be having trouble passing my dictionary to the sort function. Here is some of my code...

    VB Code:
    1. dict = bubble_sort(dict.items)
    2.  
    3. Private Function bubble_sort(dict)
    4. Dim i As Long, n As Long, tempN As Long, allOk As Boolean
    5. For n = 0 To UBound(dict)
    6.    allOk = True
    7.    For i = 0 To UBound(dict) - 1
    8.    If dict(i) > dict(i + 1) Then
    9.        allOk = False
    10.        tempN = dict(i)
    11.        dict(i) = dict(i + 1)
    12.        dict(i + 1) = tempN
    13.    End If    Next
    14.    If allOk Then Exit For
    15. Next
    16. End Function

    What do I appear to be doing incorrectly?
    Last edited by dani61265; May 15th, 2002 at 11:14 AM.

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