1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/****************************************************************************
COPYRIGHT NOTICE:
The source code in this file is provided free of charge
to the author's consulting clients. It is in the
public domain and therefore may be used by anybody for
any purpose.
AUTHOR:
Will Naylor
****************************************************************************/
#include <stdio.h>
#include <string.h>
#include "wnlib.h"
#include "wnmem.h"
#include "wnsll.h"
#include "wncmp.h"
#include "wnrndd.h"
#include "wnsort.h"
#if 1
local char string_index(string,index)
char string[];
int index;
{
return(string[index]);
}
main()
{
char string_index();
char *string;
wn_sll list,el;
wn_gpmake("no_free");
wn_gplabel("main group");
list = NULL;
wn_sllins(&list,"foo");
wn_sllins(&list,"bar");
wn_sllins(&list,"tim");
wn_sllins(&list,"mouse");
wn_sllins(&list,"ant");
wn_sllins(&list,"turkey");
wn_sort_sll(&list,(int (*)(ptr,ptr))(strcmp));
/*
wn_radix_sort_sll(&list,(string_index),(strlen));
*/
for(el=list;el!=NULL;el=el->next)
{
string = (char *)(el->contents);
printf("%s\n",string);
}
}
#endif
#if 0
local char int_index(int *pint,int index)
{
return(((char *)pint)[index]);
}
local int int_len(int *pint)
{
return(sizeof(int));
}
local int pintcmp(int *pi1,int *pi2)
{
return(wn_intcmp(*pi1,*pi2));
}
void main(void)
{
int i,r,*r_copy;
wn_sll list,el;
wn_gpmake("no_free");
wn_gplabel("main group");
list = NULL;
printf("start\n");
for(i=0;i<5000000;i++)
{
r = wn_random_int_between(0,1000000);
r_copy = wn_alloc(sizeof(int));
*r_copy = r;
wn_sllins(&list,(ptr)r_copy);
}
printf("start sort\n");
/*
wn_radix_sort_sll(&list,(int_index),(int_len));
*/
wn_sort_sll(&list,(int (*)(ptr,ptr))(pintcmp));
printf("finish sort\n");
/*
for(el=list;el!=NULL;el=el->next)
{
r_copy = el->contents;
printf("%d\n",*r_copy);
}
*/
}
#endif
|