× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



If you take a look at the generated machine code for a sort and for the for
loop, you will only see part of the savings for doing a sort. The BIG
saving is not having go do a test on every element in the array

if array(elem)>max ; /* more than max */
max=array(elem); /* update with new max */
else ; /* max is still the max */
endIf ;

as array(1) will always be the min and array(elementCount) will always be
the max after the sort.


In a message dated 4/24/2009 1:10:43 A.M. Jerusalem Daylight Time,
CRPbottle@xxxxxxxxx writes:

Adam Glauser wrote:
<<SNIP>>

By extension, you can use @max(x : y) to determine
the maximum value of an array with a number of
elements that is not known at development time.

max = array(1);
for i = 2 TO elementCount;
max = @max(max : array(i));
endfor;

Personally I prefer Asher's solution, which is both
more elegant and more efficient. To each their own.

Just curious. Why would a sort be more efficient than spinning
the array in the /for loop/ as above? Does the sort not require
effectively all the same work? Would a sort be more efficient than
the following [just for its removal of the @max function] as well?:

max=array(1);
for elem=2 to elemCount;
if array(elem)>max then /* more than max */
max=array(elem); /* update with new max */
else ; /* max is still the max */
endfor;

Regards, Chuck

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.