|
-
Aug 17th, 2000, 12:02 PM
#1
Thread Starter
Hyperactive Member
I have tried to come up with a soultion to alphabetize a list of words. I would take the ASCII codes and get the sum of the word. Then put them in order from least to greatest. Keeping all the values and then converting them back. Anyone else have suggestions?
Matt 
-
Aug 17th, 2000, 12:14 PM
#2
Lively Member
You could just use strcomp function. It will tell you if a word is less than or greater than another. Works great for this sort of thing.
-
Aug 17th, 2000, 12:28 PM
#3
_______
<?>
Code:
'you could load your words into an array
'and then sort athe array
'Remember when sorting alpha...ab5 is greater than ab49
'
Sub BubbleSortStrings(iArray As Variant)
Dim lLoop1 As Long
Dim lLoop2 As Long
Dim lTemp As String
For lLoop1 = UBound(iArray) To LBound(iArray) Step -1
For lLoop2 = LBound(iArray) + 1 To lLoop1
If iArray(lLoop2 - 1) > iArray(lLoop2) Then
lTemp = iArray(lLoop2 - 1)
iArray(lLoop2 - 1) = iArray(lLoop2)
iArray(lLoop2) = lTemp
End If
Next lLoop2
Next lLoop1
End Sub
Private Sub Command1_Click()
'Put this in the click or load or whatever
Dim myArray(6) As Variant
myArray(0) = "Jump"
myArray(1) = "William"
myArray(2) = "Zealous"
myArray(3) = "Bean"
myArray(4) = "Car"
myArray(5) = "Apple"
Call BubbleSortStrings(myArray)
For iLoop = LBound(myArray) To UBound(myArray)
Debug.Print myArray(iLoop)
Next iLoop
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Aug 17th, 2000, 12:35 PM
#4
The bubblesort os extremely inefficient in the way it works.
If the list is long, then I have a DLL that will sort alphabetically, very fast...it will do 10,000 items in under 1 second!
drop me a line if you want it.
-
Aug 17th, 2000, 02:14 PM
#5
Thread Starter
Hyperactive Member
Can you explain some of that it confuses the hell out me
Matt 
-
Aug 17th, 2000, 03:06 PM
#6
transcendental analytic
Bubble sort get's exponentially slower the more items you have in your array, this method performs aritmetically:
Code:
Sub Sort_shell(a() As String)
Dim n&, i&, j&, k&, h
n = UBound(a)
k = n \ 2
While k > 0
For i = 0 To n - k
j = i
While (j >= 0) And (a(j) > a(j + k))
h = a(j)
a(j) = a(j + k)
a(j + k) = h
If j > k Then
j = j - k
Else
j = 0
End If
Wend
Next i
k = k \ 2
Wend
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|