0 Replies - 818 Views - Last Post: 22 February 2011 - 12:58 AM Rate Topic: -----

#1 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 34
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Fun with Shell sorts, The ongoing saga!

Posted 22 February 2011 - 12:58 AM

Well i have been doing research on a sort function that i can use to sort an Index or create and Index of a specific field in a specific random access file. And have Determined that a Shell Sort function will get the job done lightning fast and efficently even if the file grows to some ungodly number of records. I have even found some "Examples" if you could call them that... Simply put they are commented, but in my mind in no where near the detail i need to figure out how to impliment them into my program... From reading this is the Gist of the information...

Open the file to be indexed, Deturmine the number of records... Create an array with that many records, read the data from the specified field into the array, run the sort, write the sort returns to the index file.

So if i want to sort say a three item file with the following:

ID UserName UserAccess
1 Administrator Administrator
2 John Doe User
3 Jane Doe User

and wanted to create an index of the 'UserName' field using the something like the below....:

'###Code Retrieved from http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/c185b322-d7de-41e6-8617-922a4323c309 Not my code!!!###'
Sub SortData()
Dim gap As Integer, doneFlag As Boolean
Dim temp As String
gap = CInt(Int(numParts / 2))
'Set the gap to half the total size
Do While gap >= 1
  'Execute the loop until the gap has been eliminated
  For index As Integer = 0 To numParts - 1 - gap
  'For items from the start up to the end of the gap, 
    If part(index) > part(index + gap) Then
    'If this item and the item that is gap distance away are out of order, 
      temp = part(index)
      part(index)  = part(index + gap)
      part(index + gap) = temp
      'swap them, and
        doneFlag = False
        'indicate that we needed to swap at least on item, so another pass will be needed
      End If
Loop Until doneFlag = True
'When that pass executes without a swap, then
gap = CInt(Int(gap / 2))
'  halve the gap
'  and repeat (until there is no gap)
End Sub

Since i have literally no clue about getting that to work maybe some one would have some advice on what i need to read on to learn more about the shell sort, or anything to better explain what is going on in the glob of confusion that is happening there above???
everything i have come up with is so darned cryptic, it seems like people don't want others to know what is going on...

any help would alleviate my confusion greatly appreciated
Jesse Fender

This post has been edited by chuckjessup: 22 February 2011 - 01:02 AM

Is This A Good Question/Topic? 0
  • +

Page 1 of 1