Vindicator209 Posted May 20, 2009 Share Posted May 20, 2009 So yeah... i'm trying to make a script that gives me medians... but I can't sort a list of numbers because it will put multiple-digit numbers in the wrong place. For example, I put in 1,2,3,10,22,31 in _ArraySort and it gives me 1,10,2,22,3,31 Any way I can put these numbers in order of least to greatest? [center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 20, 2009 Moderators Share Posted May 20, 2009 So yeah... i'm trying to make a script that gives me medians... but I can't sort a list of numbers because it will put multiple-digit numbers in the wrong place. For example, I put in 1,2,3,10,22,31 in _ArraySort and it gives me 1,10,2,22,3,31 Any way I can put these numbers in order of least to greatest?Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) Local $i_ub = UBound($n_array) For $i_count = $i_start To $i_ub - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
jerem488 Posted October 12, 2009 Share Posted October 12, 2009 Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) Local $i_ub = UBound($n_array) For $i_count = $i_start To $i_ub - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFunc Hi How do we use this function ? Thanks in advance Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
Valuater Posted October 12, 2009 Share Posted October 12, 2009 Like This... #include <array.au3> $Array = StringSplit("2,5,3,4,6,1,8,9,7", ",") _ArraySortNum($Array) _ArrayDisplay($Array, "Sorted Array") Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) Local $i_ub = UBound($n_array) For $i_count = $i_start To $i_ub - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFunc ;==>_ArraySortNum 8) AnonymousX 1 Link to comment Share on other sites More sharing options...
jerem488 Posted October 13, 2009 Share Posted October 13, 2009 Like This... #include <array.au3> $Array = StringSplit("2,5,3,4,6,1,8,9,7", ",") _ArraySortNum($Array) _ArrayDisplay($Array, "Sorted Array") Func _ArraySortNum(ByRef $n_array, $i_descending = 0, $i_start = 1) Local $i_ub = UBound($n_array) For $i_count = $i_start To $i_ub - 2 Local $i_se = $i_count If $i_descending Then For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) < Number($n_array[$x_count]) Then $i_se = $x_count Next Else For $x_count = $i_count To $i_ub - 1 If Number($n_array[$i_se]) > Number($n_array[$x_count]) Then $i_se = $x_count Next EndIf Local $i_hld = $n_array[$i_count] $n_array[$i_count] = $n_array[$i_se] $n_array[$i_se] = $i_hld Next EndFunc ;==>_ArraySortNum 8) Very thanks Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
rudi Posted February 25, 2016 Share Posted February 25, 2016 (edited) Hi. Quite a time ago I had to search for all elements in one large for all the occurences in another, really *HUGE* array. To Speed up the whole process, I sorted both Arrays, preserving positions in the 2nd arrays's element list (2D). By this I could skip the searching in the 2nd Array after looking up some few elements and increasing the "start value Position" in the 2nd Array to the next plausible one Duplicates in both Arrays are possible. Search-one-array-in-another.au3. Regards, Rudi. Edited February 25, 2016 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! 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