Category : C Source Code
Archive   : C-TOOLBX.ZIP
Filename : INSERT.C

 
Output of file : INSERT.C contained in archive : C-TOOLBX.ZIP
/* insert.c - insertion sort function */
/* uses pointers to actual data elements and a compare function */
#include "stdio.h"

int insert(pa,na,pcomp)
char *pa[] ; /* number of pointers to elements to be sorted */
int na ; /* number of elements to be sorted */
int (*pcomp) () ; /* pointer to compare function */
{
int i ; /* indeces for loops */
int j ; /* for inner loop - optomize */
char *ptemp ; /* temporary storage for one pointer */

for( i=1 ; i < na ; i = i + 1 )
{ /* insert the i-th element into the storage array */
ptemp = pa[i] ;
j = j - 1 ;
while( (j >= 0 ) && ( (*pcomp) (ptemp,pa[j]) <= 0 ) )
{ pa[j+1] = pa[j] ;
j = j - 1 ;
}
pa[j+1] = ptemp ;
}
}





  3 Responses to “Category : C Source Code
Archive   : C-TOOLBX.ZIP
Filename : INSERT.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/