I am just wondering what is the most effecient way to pick the lowest and highest numbers from a list? For example, I have four numbers linked to four datums, and I need to select whichever datum has the lowest number. What would be the most effective way to do this?
~Polatrite~
ID:153011
![]() Mar 30 2005, 9:02 pm
|
|
I am just wondering what is the most effecient way to pick the lowest and highest numbers from a list? For example, I have four numbers linked to four datums, and I need to select whichever datum has the lowest number. What would be the most effective way to do this? If your list is unsorted you unfortunantly need to check every item in the list. If you're looking for the min/max a lot more than you are adding items to the list you might just want to keep the list sorted. Then picking the min/max becomes trivial. |
Crispy wrote:
On a slightly unrelated note... I looked at the reference entry for min() while writing this post, and realised you can also pass an actual /list to it instead of just a series of numbers (i.e. min(list(1,2,3)) is equivalent to min(1,2,3)). Me likes. =) Man, I checked the reference for at least 15 minutes looking for something. How did I miss this? Just what I needed! |
Getting the first and last items in a list is really straightforward... L[1] and L[length(L)] respectively. For the latter (a var belonging to the datums), you have to loop through the whole list and test the variable on each datum:
On a slightly unrelated note... I looked at the reference entry for min() while writing this post, and realised you can also pass an actual /list to it instead of just a series of numbers (i.e. min(list(1,2,3)) is equivalent to min(1,2,3)). Me likes. =)