_Kurt Posted September 8, 2007 Share Posted September 8, 2007 (edited) 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:expandcollapse popup#include <Array.au3> ;Used only for _Arraydisplay Local $Array[11] $Array[0] = "5 is number five" $Array[1] = "" $Array[2] = "2" $Array[3] = "1 I'm #1 :)" $Array[4] = "4" $Array[5] = "3.. Blah" $Array[6] = "D-erek" $Array[7] = "A-lex" $Array[8] = "E-ric" $Array[9] = "C-hris" $Array[10] = "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 EndFuncEDIT: Also forgot to mention, blank strings ( $array[x] = "" ) will be put at the start of the array.Kurt Edited September 8, 2007 by _Kurt Awaiting Diablo III.. Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted September 9, 2007 Share Posted September 9, 2007 (edited) Nice idea, I assume using a GUI listview shortens the code quite abit eh? Edited September 9, 2007 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Xand3r Posted September 9, 2007 Share Posted September 9, 2007 #include<Array.au3> Dim $arrayz[7] $arrayz[0]="0" $arrayz[1]="" $arrayz[2]="14" $arrayz[3]="asd" $arrayz[4]="nvc" $arrayz[5]="A34" $arrayz[6]="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 Link to comment Share on other sites More sharing options...
Developers Jos Posted September 9, 2007 Developers Share Posted September 9, 2007 (edited) ... what is the difference with this and _ArraySort() ? Edited September 9, 2007 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
_Kurt Posted September 9, 2007 Author Share Posted September 9, 2007 Wow, very cool function, alex. Kurt Awaiting Diablo III.. Link to comment Share on other sites More sharing options...
Xand3r Posted September 9, 2007 Share Posted September 9, 2007 ... 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 Link to comment Share on other sites More sharing options...
_Kurt Posted September 9, 2007 Author Share Posted September 9, 2007 ... what is the difference with this and _ArraySort() ?Oh, I was not familiar with this function. Heh, sorry about that. Kurt Awaiting Diablo III.. Link to comment Share on other sites More sharing options...
-Ultima- Posted September 9, 2007 Share Posted September 9, 2007 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. [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
Xand3r Posted September 9, 2007 Share Posted September 9, 2007 (edited) 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. expandcollapse popup#include<Array.au3> Dim $array[101][2] For $i=0 To 100 Dim $arrayz[7] $arrayz[0]="0" $arrayz[1]="" $arrayz[2]="14" $arrayz[3]="asd" $arrayz[4]="nvc" $arrayz[5]="A34" $arrayz[6]="f4" $asd=TimerInit() order($arrayz) $array[$i][0]=TimerDiff($asd) $arrayz[0]="0" $arrayz[1]="" $arrayz[2]="14" $arrayz[3]="asd" $arrayz[4]="nvc" $arrayz[5]="A34" $arrayz[6]="f4" $asd2=TimerInit() _ArraySort($arrayz) $array[$i][1]=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 EndFuncoÝ÷ Úȳz¬¥©ì·)^ Edited September 9, 2007 by alexmadman 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 Link to comment Share on other sites More sharing options...
-Ultima- Posted September 9, 2007 Share Posted September 9, 2007 (edited) 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 September 9, 2007 by -Ultima- [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ] Link to comment Share on other sites More sharing options...
Developers Jos Posted September 9, 2007 Developers Share Posted September 9, 2007 now try something more substantial to sort... like this #include<Array.au3> Dim $array[101][2] For $i = 0 To 20 Dim $array1[100],$array2[100] For $x = 0 to UBound($array1)-1 $array1[$x] = Random(1,99999999) $array2[$x] = $array1[$x] Next $asd = TimerInit() order($array1) $array[$i][0] = TimerDiff($asd) $asd2 = TimerInit() _ArraySort($array2) $array[$i][1] = 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 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
randallc Posted September 9, 2007 Share Posted September 9, 2007 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 [0]|304.670732074067|31.4530001861691 [1]|308.610872273697|36.5806237379885 [2]|364.124882570279|33.6781960217102 [3]|286.373674977445|31.4495592805281 [4]|303.292049148635|35.1598755531369 [5]|295.63468329777|34.7648255022985 ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Xand3r Posted September 9, 2007 Share Posted September 9, 2007 (edited) 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 ) Edited September 9, 2007 by alexmadman 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 Link to comment Share on other sites More sharing options...
Developers Jos Posted September 9, 2007 Developers Share Posted September 9, 2007 (edited) 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 September 9, 2007 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now