IceChat Forums

IceChat 5 Scripting => Scripting => Topic started by: DarkStar on January 12, 2007, 09:09:51 PM

Title: Alphabatize array
Post by: DarkStar 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.
Title: Re: Alphabatize array
Post by: Snerf 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.
Title: Re: Alphabatize array
Post by: DarkStar 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 (http://www.visualbasicscript.com/m_36231/tm.htm) 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.