Subversion Repositories PlanixRsrch.SVN

Compare Revisions

Ignore whitespace Rev 328 → Rev 329

/trunk/libmavl/mavtest.c
36,7 → 36,20
* EXAMPLE 1 Create an AVL which stores just integer values.
*/
 
static float
calc_depth(int numvals)
{
int i;
unsigned int r=1;
for (i=0; i<64; i++){
if (r>(unsigned int)numvals)
return (float)((double)i*1.44);
r=r<<1;
}
return (float)0.0;
}
 
 
/* Compare function to compare integers */
static int
cmp(const void *v1, const void *v2)
55,11 → 68,15
static void pcb(char*dst,struct mavlnode *n)
{
int *d = mavlnode_dataptr(n);
(void) sprintf(dst,"%d (%d)",*d,n->bal);
(void) sprintf(dst,"(%d) %d ",n->bal,*d);
}
 
struct mavl * the_t;
void the_print()
{
mavl_print(the_t,pcb,150);
}
 
 
int
main(int argc,char ** argv)
{
92,6 → 109,7
* function, so second argument to mavl_create is NULL.
*/
t = mavl_create(cmp, NULL, sizeof(int));
the_t = t;
if (t == NULL) {
(void)fprintf(stderr,
"Can't create struct mavl*: %s\n",
111,14 → 129,18
(void)mavl_insert(t, &insval, &exists);
 
(void)printf("%d. -----------------------------------------\n",i);
mavl_print(t,pcb,80);
mavl_print(t,pcb,150);
}
 
for(i=i+1; i<argc; i++){
del = atoi(argv[i]);
mavl_del(t,&del);
mavl_print(t,pcb,80);
mavl_print(t,pcb,150);
}
 
printf("Real Depth: %d, Max Depth: %f (n:%d)\n",
mavl_get_depth(t),
calc_depth(t->count),t->count);
/*
if (del!=-1){
mavl_del(t,&del);
152,5 → 174,6
(void)mavliter_next(&it);
}
(void)printf("\n");
 
return 0;
}