Author Topic: Alphabatize array  (Read 5452 times)

DarkStar

  • Full Member
  • ***
  • Posts: 135
  • Scripts for Praise
    • CorpseCorp
Alphabatize array
« on: January 12, 2007, 09:09:51 PM »
Is there a simple way to do it? If there isn't I think I'll have to come up with some way to do so.
This message brought to you by the Wonderful Wizard of Oz.

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Alphabatize array
« Reply #1 on: January 12, 2007, 09:13:34 PM »
No simple way at all.
Have to use some kind of a sorter. Bubble Sort or QuickSort, whichever you want, plenty of examples of em out there.
The IceChat God

DarkStar

  • Full Member
  • ***
  • Posts: 135
  • Scripts for Praise
    • CorpseCorp
Re: Alphabatize array
« Reply #2 on: January 13, 2007, 12:40:59 AM »
Well, I dont really understand it, But I found something that works. I used the "old sort function" from this page.

Quote from: Input
/! sorttest cat bird apple

Quote from: output
apple
bird
cat


Code: [Select]
sub sorttest(msg)
myarray=split(msg," ")
myarray=InsertionSort(myarray)
for a=lbound(myarray) to ubound(myarray)
SendCommand "/echo -a " & myarray(a)
next
end sub

Function InsertionSort(arrX)
Dim nUB : nUB = UBound(arrX)
Dim i, j, v
For i=1 To nUB
   v=arrX(i)
   j=i
   Do While arrX(j-1) > v
      arrX(j) = arrX(j-1)
      j=j-1
      If j<=0 Then
      Exit Do
      End If
   Loop
   arrX(j) = v
Next
InsertionSort=arrX
End Function

Now i just gotta figure out how that function works. If you see anything in it that might help me understand it would be apreciated.
This message brought to you by the Wonderful Wizard of Oz.