× 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.


  • Subject: RE: New RPG Redbook (was Sub Files).(and quick sort)
  • From: Jon.Paris@xxxxxxxxxx
  • Date: Tue, 14 Dec 1999 10:42:56 -0500



 >> Here's a test program I wrote last year to play with qsort().  Don't vouch
for the quality or style.

Just a couple of comments to help others understand some of the additional
potential of the functionality here.

First the invocation of qsort can use the BIFs directly since the parms are
passed by value - there is no need to copy the BIF result to a variable.

   C                   callp     sortit( %Addr(array) : numelems     :
   C                             %Size(array) : %PAddr('COMPFUNC') )

One of the benefits of qsort and bsearch is that they don't have to sort/search
the whole array so the value "x" would be better than "numelems" - although in
your example they are the same anyway <grin>.

The based variables in the compare procedure can be coded using LIKE - that way
there's no chance for a mis-match.  I also like to make a point of _always_
leaving at least one space after the D spec Id - that way not all of your
variables read as if they started with the letter D <bg>


    D key              s                   based(lookfor) Like(Array)
    D arrelt           s                   based(arreltptr) Like(Array)

Last but not least don't forget that these functions can be used to sort/search
a Multiple Occurrence Data Structure every bit as easily as an array.


+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


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.