home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_11_04
/
1104111c
< prev
next >
Wrap
Text File
|
1993-02-05
|
601b
|
37 lines
/* select2.c: Use the selection sort function */
#include <stdio.h>
#define NELEMS 4
extern void ssort(void *, size_t, size_t,
int (*)(const void *,const void *));
static int comp(const void *, const void *);
main()
{
size_t i;
int a[NELEMS] = {40, 12, 37, 15};
ssort(a,NELEMS,sizeof a[0],comp);
for (i = 0; i < NELEMS; ++i)
printf("%d\n",a[i]);
return 0;
}
static int comp(const void *p1, const void *p2)
{
int a = * (int *) p1;
int b = * (int *) p2;
return a - b;
}
/* Output:
12
15
37
40
*/