member42 Posted December 31, 2014 Share Posted December 31, 2014 (edited) Hello, I've one question i've done some basic function to find the max / min value in an array like this for the findMax: ( same logic for find min but using _min function) Func findPremier($tab, $kl) if _Max($tab[$kl],$tab[$kl+1],$tab[$kl+2],$tab[$kl+3]) = $tab[$kl] Then return $kl ElseIf _Max($tab[$kl],$tab[$kl+1],$tab[$kl+2],$tab[$kl+3]) = $tab[$kl+1] Then return $kl+1 elseif _Max($tab[$kl],$tab[$kl+1],$tab[$kl+2],$tab[$kl+3]) = $tab[$kl+2] Then return $kl+2 Else return $kl+3 EndIf EndFunc The array is not order and i can't be ordered( unless there is no other solution) How can i find the second max value of those 4 value ? For example how can i find "5" in this array: [12;1;3;5] ? Thanks if anyone can help. I know of course i could do this:( but prefer avoid an ordering) Func findSecond($tab, $kl) Order($tab) return $tab[1]; EndFunc Edited December 31, 2014 by member42 Link to comment Share on other sites More sharing options...
Yashied Posted December 31, 2014 Share Posted December 31, 2014 (edited) Dim $Array[4] = [12, 1, 3, 5] $Min = $Array[0] $Max = $Array[0] For $i = 2 To UBound($Array) - 1 If $Array[$i] > $Max Then $Max = $Array[$i] If $Array[$i] < $Min Then $Min = $Array[$i] Next ConsoleWrite('Min = ' & $Min & @CR) ConsoleWrite('Max = ' & $Max & @CR) Edited December 31, 2014 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
member42 Posted December 31, 2014 Author Share Posted December 31, 2014 (edited) That's the function min/max same as _Min and _Max in the library. i Need the second max value in this case 5 maybe i need to do something like that: FindMax(array) If array[0] != findMax(array) SecondMax=array[0] else SecondMax=array[1] for i=0 to unbound(array)-1 step 1 if array[i] > secondMax and array[i] != findMax(array) secondMax = array[i] Edited December 31, 2014 by member42 Link to comment Share on other sites More sharing options...
Developers Jos Posted December 31, 2014 Developers Share Posted December 31, 2014 (edited) Something like this?: #include <Array.au3> Local $aObjs = 1 Dim $a[5]= [12,1,3,5] _ArraySort($a,1) ; Show second entry in the array ConsoleWrite('$a[1] = ' & $a[1] & @CRLF) Jos Edited December 31, 2014 by Jos 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...
member42 Posted December 31, 2014 Author Share Posted December 31, 2014 Yeah but in this soltuioni must sort the array and i highly prefer to not sort the array ( because if i should also sort 4 others array =/ and other boring stuff =/ ) I've only 4 elements so it's even better to hard code all the solution than this Link to comment Share on other sites More sharing options...
Solution jguinch Posted December 31, 2014 Solution Share Posted December 31, 2014 ? Local $Array[4] = [12, 1, 3, 5] Local $iMax Local $iMax2 For $i = 0 To UBound($Array) - 1 If $Array[$i] > $iMax Then $iMax2 = $iMax $iMax = $Array[$i] ElseIf $Array[$i] > $iMax2 Then $iMax2 = $Array[$i] EndIf Next ConsoleWrite("Second max value : " & $iMax2) member42 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
johnmcloud Posted December 31, 2014 Share Posted December 31, 2014 (edited) Local $Array[10] = [12, 27, 20, 120, 111, 215, 54, 8, 77, 114] Local $iMAX = $Array[0] Local $iMIN = $Array[0] Local $iMAX_Next = $Array[0] For $i = 0 To UBound($Array) - 1 If $Array[$i] < $iMIN Then $iMIN = $Array[$i] If $Array[$i] > $iMAX Then $iMAX_Next = $iMAX $iMAX = $Array[$i] ElseIf $Array[$i] < $iMAX And $Array[$i] > $iMAX_Next Then $iMAX_Next = $Array[$i] EndIf Next ConsoleWrite("Maximum value is : " & $iMAX & @CR) ConsoleWrite("Minimum value is : " & $iMIN & @CR) ConsoleWrite("Second maximum value is : " & $iMAX_Next & @CR) Edited December 31, 2014 by johnmcloud member42 1 Link to comment Share on other sites More sharing options...
Developers Jos Posted December 31, 2014 Developers Share Posted December 31, 2014 (edited) Yeah but in this soltuioni must sort the array and i highly prefer to not sort the array ( because if i should also sort 4 others array =/ and other boring stuff =/ ) I've only 4 elements so it's even better to hard code all the solution than this Don't understand the issue. Just put the logic in a UDF and return the found value so you can reuse the logic on other arrays. something like: #include <Array.au3> Local $aObjs = 1 Dim $a[5]= [12,1,3,5] Dim $b[5]= [1,21,13,5] ConsoleWrite("2nd value for $a=" & Get2ndValue($a) & @CRLF) ConsoleWrite("2nd value for $b=" & Get2ndValue($b) & @CRLF) Func Get2ndValue($aI) Local $aIS = $aI _ArraySort($aIS,1) Return $aIS[1] EndFunc Jos Edited December 31, 2014 by Jos 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...
member42 Posted December 31, 2014 Author Share Posted December 31, 2014 Thanks folks! @Jos the problem is that i've few array linked at this one for example: array1 = playerName['test',"test2','test3','test4'] array2= playerScore['10",'120","56","42"] array3= playerTotalScore["1110","800","587","950"] If i sort the array2 i also need to swap all the others link to this one. So i can't afford this ( but ofc it's possible but more work to do so) Thanks again to everyone. I've almost done 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