/** Test the collection class **/ #include #include "collection.h" int *list; int N = 100; extern double drand48(); int rand() { return 100*drand48(); } int *ItemKey( int *item ) { return item; } int KeyCmp( int *a, int *b ) { if ( *a < *b ) return -1; else if ( *a == *b ) return 0; else return 1; } void GenList( int n ) { int i; list = (int *)malloc( n*sizeof( int ) ); for(i=0;i=0;i--) { DeleteFromCollection( c, &list[i] ); if ( FindInCollection( c, &list[i] ) ) { printf("Delete failure item %d, value %d\n", i, list[i] ); } } } void main( int argc, char *argv[] ) { collection c; if ( argc > 1 ) N = atoi( argv[1] ); printf("Collection size %d\n", N ); GenList( N ); c = ConsCollection( N, sizeof( int ) ); AddAll( c ); printf("Added %d items\n", N ); CheckAll( c ); printf("Checked %d items\n", N ); DeleteAll_1( c ); printf("Deleted all items\n" ); AddAll( c ); printf("Added %d items\n", N ); DeleteAll_2( c ); printf("Deleted all items\n" ); }