OK, I agree (finally).
Thanks for everybody's patience with me.
So a for loop using %Parms() would be the fastest. And overlaying the parms
into a DS with an array overlay (which would then not be sorted) would
allow the elements to be compared by array value. Each element 26 chars long
would allow the min/max to handle numbers, dates, times, small strings, and
time stamps. For everything else, there's MasterCard.
max = array(1);
for n = 2 to %Parms();
if array(n) > max;
max = array(n) ;
endIf ;
endFor;
return max;
the program that called the above proc would then have to assign max (a 26
char string) to the actual type that was needed. So much for elegance.
In a message dated 4/25/2009 1:21:40 A.M. Jerusalem Daylight Time,
shc@xxxxxxxxxxxxxxxxx writes:
On 24/04/2009, at 10:56 PM, Asher613Smith@xxxxxxx wrote:
I may stand corrected. Or maybe not. Needs more investigation,
because I
know that doing a test on each pass through the loop is costly. The
sort can
be optimized.
Doesn't need any investigation at all. Consider how any sort works. It
must compare at least two elements to determine their relative order.
It must perform a comparison on all elements being sorted. It may
perform that comparison multiple time because each comparison may
result in a change to the elements ordinal position.
Even if the low-level code unrolls (i.e., optimises) the loop into a
sequential set of operations it still has to perform a comparison on
all the elements.
This is true for any kind of sort (exchange, selection, insertion,
enumeration, etc.) The only real difference between these sorts is
what they do with the result of the comparison.
A comparison is a test--exactly the same as an IF test in your own
code-- thus a sort of any description will cost at least as much as
testing the elements directly in your own code.
Even a special-purpose sort that is optimised for the particular data
in question cannot perform faster than O(n). For a general-purpose
sort that will only happen if the elements are already in the correct
sequence.
Now if you can create a general-purpose sort that is faster than O(n)
then patent it and make your fortune.
Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists
http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------
--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
http://archive.midrange.com/rpg400-l.
**************Access 350+ FREE radio stations anytime from anywhere on the
web. Get the Radio Toolbar!
(
http://toolbar.aol.com/aolradio/download.html?ncid=emlcntusdown00000003)
As an Amazon Associate we earn from qualifying purchases.