Hey guys,
How would I go about sorting an Array of Strings, using either a selection sort or a insertion sort?
I have written an insertion sort, but i only works for integers. How can i modify it to work with strings.
Public Sub InsertionSort(ByVal numitems As Integer) Dim currentitem, currentdataitem, comparison, shuffleitem As Integer Dim finish As Boolean currentitem = 1 While currentitem <= (numitems - 1) currentdataitem = item(currentitem) comparison = 0 finish = False While comparison < currentitem And finish = False If currentdataitem < item(comparison) Then shuffleitem = currentitem While shuffleitem > comparison item(shuffleitem) = item(shuffleitem - 1) shuffleitem = shuffleitem - 1 Wend item(comparison) = currentdataitem finish = True End If comparison = comparison + 1 Wend currentitem = currentitem + 1 Wend End Sub
Any help is appreciated.
Thanks,
Jem00
Here is one sort...
http://www.vbforums.com/showthread.php?t=231925&highlight=sort
and a list of sorting routines...
http://www.vbforums.com/showthread.php?t=473677&highlight=sort
Good Luck
Thanks, but I need to be able to do it with an insertion or selection sort.
Could you guide me as to what i should do?
I figured it out. I just used the same algorithm but converted the data types. Geez i'm stupid. Sorry guys.
Hopefully someone else might find this thread useful. Thanks for your help