PDA

View Full Version : Sort !


OMID SOFT
04-30-04, 11:23 PM
I am going to sort a text file by name.
Which type of sort is better ? (Bubble,..., etc ?)
And is here anyone that have a VB code of it ?
Thank you.
Omid Soroori of OMID SOFT.

kasic
05-01-04, 06:23 AM
yes I think that Bubble sort is the best for sorting things (or easiest :)) I know how to sort number, but text hmmm I dont know, but I think that algorithm is the same...

try to look at this link...
http://www.planet-source-code.com/vb/scripts/BrowseCategoryOrSearchResults.asp?optSort=Alphabet ical&blnWorldDropDownUsed=TRUE&txtMaxNumberOfEntriesPerPage=10&blnResetAllVariables=TRUE&txtCriteria=bubble+sort&lngWId=1&B1=Quick+Search

kebo
05-01-04, 10:09 AM
yes I think that Bubble sort is the best for sorting things (or easiest :)) I know how to sort number, but text hmmm I dont know, but I think that algorithm is the same...


The bubble sort albeit effective is probably one of the slowest soft routines. Try the code below. As far as sorting strings, they get sorted by their ASCII values so that "<" < "=" and "B" > "A" etc.

Public Sub QuickSort(SortList As Variant, ByVal First As Integer, ByVal Last As Integer)
Dim Low As Integer, High As Integer 'Use Integer for lists up to 32,767 entries.
Dim Temp As Variant, TestElement As Variant 'Variant can handle any type of list.

Low = First
High = Last
TestElement = SortList((First + Last) / 2)'Select an element from the middle.
Do
Do While SortList(Low)< TestElement 'Find lowest element that is >= TestElement.
Low = Low + 1
Loop
Do While SortList(High)> TestElement 'Find highest element that is <= TestElement.
High = High - 1
Loop
If (Low <= High) Then 'If not done,
Temp = SortList(Low) ' Swap the elements.
SortList(Low) = SortList(High)
SortList(High) = Temp
Low = Low + 1
High = High - 1
End If
Loop While (Low <= High)
If (First < High) Then QuickSort SortList, First, High
If (Low < Last) Then QuickSort SortList, Low, Last
End Sub

kasic
05-01-04, 10:20 AM
I didn't knew that the Bubble sort is most slowest algorithm for sorting... sorry for that... ;)