home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-3 / QSORT.TIP < prev    next >
Text File  |  2000-06-30  |  1KB  |  33 lines

  1.  
  2.  
  3. Note to BDS C Users Who Use the "qsort" Library Function:
  4.     (From Leor Zolman, Feb 1982)
  5.  
  6.  
  7. The low-level swap function that qsort uses, called "_swp", is pretty
  8. inefficient. A version that works much more quickly is given below, but
  9. note that this method necessarily requires that some upper maximum be set
  10. on the size ("width") of a single object of the class being sorted. The
  11. new _swp function is as follows:
  12.  
  13.  
  14. -------------------------------------------------------------------------------
  15. #define MAX_WIDTH 1000        /* largest allowable width */
  16.  
  17. _swp(width, a, b);
  18. {
  19.     char swapbuf[MAX_WIDTH];
  20.     movmem(a,swapbuf,width);    /* simply swap through the temporary */
  21.     movmem(b,a,width);        /* buffer allocated on the stack     */
  22.     movmem(swapbuf,b,width);
  23. }
  24.  
  25. -------------------------------------------------------------------------------
  26. To install this modification, replace the _swp function in STDLIB1.C with
  27. this version, recompile STDLIB1.C, and use the librarian (CLIB) to delete
  28. the old version of "_swp" in DEFF.CRL and replace it with the new one from
  29. STDLIB1.CRL. And make sure that the MAX_WIDTH define is set so that you're
  30. never likely to want to sort object of larger size. If you DO, remember to
  31. go back and change the define....
  32.     -leor
  33.