## Recommended Posts

Made a small, simple, easy to use function that will arrange your arrays alphanumerically. I'm not sure if anyone had made something like this before, but by searching the forum I had not seen something like this.

Example:

```#include <Array.au3> ;Used only for _Arraydisplay

Local \$Array
\$Array = "5 is number five"
\$Array = ""
\$Array = "2"
\$Array = "1 I'm #1 :)"
\$Array = "4"
\$Array = "3.. Blah"
\$Array = "D-erek"
\$Array = "A-lex"
\$Array = "E-ric"
\$Array = "C-hris"
\$Array = "B-ob"
\$NewArray = _ArrayArrangeAlNum(\$Array)
_ArrayDisplay(\$NewArray, "\$NewArray")oÝ÷ Ù8^éÜ¶*'jëh×6#include <GUIList.au3>

Func _ArrayArrangeAlNum(\$Array)
If NOT IsArray(\$Array) Then Return 0
Local \$Str = "", \$NewArray[UBound(\$Array)], \$Num = 0
For \$i = 0 To UBound(\$Array)-1
If \$Array[\$i] <> "" Then
\$Str &=  "|" & \$Array[\$i]
Else
\$NewArray[\$Num] = ""
\$Num = \$Num+1
EndIf
Next
\$A = GUICreate("")
\$B = GuiCtrlCreateList("", 0, 0, 300, 300, 0x0002)
GUICtrlSetData(-1,\$Str)
For \$i = \$Num To UBound(\$Array)-1
\$NewArray[\$i] = _GUICtrlListGetText(\$B, \$i-\$Num)
Next
GUIDelete(\$A)
Return \$NewArray
EndFunc```

EDIT: Also forgot to mention, blank strings ( \$array[x] = "" ) will be put at the start of the array.

Kurt

Edited by _Kurt

Awaiting Diablo III..

##### Share on other sites

Nice idea, I assume using a GUI listview shortens the code quite abit eh?

Edited by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

##### Share on other sites

```#include<Array.au3>
Dim \$arrayz
\$arrayz="0"
\$arrayz=""
\$arrayz="14"
\$arrayz="asd"
\$arrayz="nvc"
\$arrayz="A34"
\$arrayz="f4"

order(\$arrayz)
_ArrayDisplay(\$arrayz)

Func order(ByRef \$array)
Do
\$s=0
For \$i=0 To UBound(\$array)-2
If \$array[\$i]>\$array[\$i+1] Then
\$temp=\$array[\$i]
\$array[\$i]=\$array[\$i+1]
\$array[\$i+1]=\$temp
\$s=1
EndIf
Next
Until \$s=0
EndFunc```

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

##### Share on other sites ... what is the difference with this and _ArraySort() ? Edited by JdeB

Live for the present,
Dream of the future,
Learn from the past. ##### Share on other sites ... what is the difference with this and _ArraySort() ?

well... wana bet it works faster?... Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

##### Share on other sites ... what is the difference with this and _ArraySort() ?

Oh, I was not familiar with this function. Heh, sorry about that. Kurt

Awaiting Diablo III..

##### Share on other sites

well... wana bet it works faster?... I'd place my bet on it being slower -- much slower. There's too much overhead in working with a list control just for sorting.

##### Share on other sites

I'd place my bet on it being slower -- much slower. There's too much overhead in working with a list control just for sorting.

```#include<Array.au3>
Dim \$array

For \$i=0 To 100
Dim \$arrayz
\$arrayz="0"
\$arrayz=""
\$arrayz="14"
\$arrayz="asd"
\$arrayz="nvc"
\$arrayz="A34"
\$arrayz="f4"

\$asd=TimerInit()
order(\$arrayz)
\$array[\$i]=TimerDiff(\$asd)

\$arrayz="0"
\$arrayz=""
\$arrayz="14"
\$arrayz="asd"
\$arrayz="nvc"
\$arrayz="A34"
\$arrayz="f4"
\$asd2=TimerInit()
_ArraySort(\$arrayz)
\$array[\$i]=TimerDiff(\$asd2)
Next
_ArrayDisplay(\$array)
Func order(ByRef \$array)
Do
\$s=0
For \$i=0 To UBound(\$array)-2
If \$array[\$i]>\$array[\$i+1] Then
\$temp=\$array[\$i]
\$array[\$i]=\$array[\$i+1]
\$array[\$i+1]=\$temp
\$s=1
EndIf
Next
Until \$s=0

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

##### Share on other sites

I'm not sure what you're getting all worked up about. It looked to me like JdeB was asking what the difference was between _Kurt's function and _ArraySort(), and I said it was slower. I never even looked at your function. I thought that was pretty obvious, considering the fact that I mentioned lists in the first place.

Edited by -Ultima-

##### Share on other sites

now try something more substantial to sort... like this ```#include<Array.au3>
Dim \$array
For \$i = 0 To 20
Dim \$array1,\$array2
For \$x = 0 to UBound(\$array1)-1
\$array1[\$x] = Random(1,99999999)
\$array2[\$x] = \$array1[\$x]
Next
\$asd = TimerInit()
order(\$array1)
\$array[\$i] = TimerDiff(\$asd)
\$asd2 = TimerInit()
_ArraySort(\$array2)
\$array[\$i] = TimerDiff(\$asd2)
Next
_ArrayDisplay(\$array)
Func order(ByRef \$array)
Do
\$s = 0
For \$i = 0 To UBound(\$array) - 2
If \$array[\$i] > \$array[\$i + 1] Then
\$temp = \$array[\$i]
\$array[\$i] = \$array[\$i + 1]
\$array[\$i + 1] = \$temp
\$s = 1
EndIf
Next
Until \$s = 0
EndFunc  ;==>order```

Live for the present,
Dream of the future,
Learn from the past. ##### Share on other sites

Hi,

jDeb is opinting out that larger arrays will benefit from the quicksort algorithm in ArraySort... immensely.. - here's 199 random elements; try 2000 and you'll spend a long time..

Best, randall

|304.670732074067|31.4530001861691

|308.610872273697|36.5806237379885

|364.124882570279|33.6781960217102

|286.373674977445|31.4495592805281

|303.292049148635|35.1598755531369

|295.63468329777|34.7648255022985

##### Share on other sites

that's a very normal thing.... my func is for small things....

as you can see ... it will pass through the whole array lots of times...(btw i learnt that func in school )

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

##### Share on other sites

that's a very normal thing.... my func is for small things....

Not sure where small ends and large starts but running the test you submitted it takes your bubblesort 0.00174 secs and _ArraySort() 0.00264 sec on my PC per array sort operation.

I would use the supplied UDF anyways for Small arrays ... Edited by JdeB

Live for the present,
Dream of the future,
Learn from the past. ## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...