In kdtree_main.c, we implement case c as follows:
case 'c':
printf("counting ...\n");
for(i=0; i<numdims; i++){
printf("%d-th attr. low value= ", i);
scanf("%lf", &val);
vecput( vpLow, i, val);
}
for (i=0; i<numdims; i++){
printf("%d-th attr. high value= ", i);
scanf("%lf", &val);
vecput( vpHigh, i, val);
}
printf(" counting - low values: ");
vecprint( vpLow);
printf(" counting - high values: ");
vecprint( vpHigh);
int cnt=0;
rcount(root, vpLow, vpHigh, 0, &cnt);
printf("%d points found.\n", cnt);
break;
In kdtree.c, we add the rcount function:
void rcount(TREENODE *subroot, VECTOR *vpLow, VECTOR *vpHigh, int level, int *count){
int numdims;
if( subroot != NULL ){
numdims = (subroot->pvec)->len;
if( contains( vpLow, vpHigh, subroot->pvec ) ){
(*count)++;
vecprint(subroot->pvec);
}
if( (vpLow->vec)[level] <= ((subroot->pvec)->vec)[level] ){
rcount( subroot->left, vpLow, vpHigh, (level+1)% numdims, count);
}
if( (vpHigh->vec)[level] > ((subroot->pvec)->vec)[level] ){
rcount( subroot->right, vpLow, vpHigh, (level+1)% numdims, count);
}
}
return;
}