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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.