int rec_search(int **array, int *S, int *V, int x, int n, int *rest, double t, int *f, int c) { int nS[2]; int i, j; double d = dist(S, array[x]); if(*f == 1){ return 0; }else if(comp(t+d, dist(array[x], V)) == 0){ c++; if(n == c){ *f = 1; return 0; } t += d; rest[x] = 0; nS[0] = array[x][0]; nS[1] = array[x][1]; for(i = 0; i < n; i++){ if(rest[i]){ int *nrest = (int *)calloc(n, sizeof(int)); for(j = 0; j < n; j++) nrest[j] = rest[j]; nrest[i] = 1; rec_search(array, nS, V, i, n, nrest, t, f, c); } } } return 0; }
/**************************************************************************** * search() utility function * ****************************************************************************/ bst::Position bst::rec_search ( Node * u , Data_t k ) const { if(u->left == NULL && u->right == NULL) { return Position(u); } else if(u->data == k) { return Position(u); } else if(k < u->data) { return rec_search(u->left, k); } else if(k > u->data) { return rec_search(u->right, k); } }
/**************************************************************************** * Search tree for the given value * ****************************************************************************/ bst::Position bst::search( Data_t k ) const { if(_root != NULL) { return rec_search(_root, k ); } else { return Position(NULL); } }
int full_search(int **array, int *S, int *V, int n) { int i, j = 0; int *f; f = &j; int *rest; for(i = 0; i < n; i++){ if(comp(dist(array[i], S), dist(array[i], V)) == 1){ return 1; } } rest = (int *)calloc(n, sizeof(int)); for(i = 0; i < n; i++) rest[i] = 1; for(i = 0; i < n; i++){ rec_search(array, S, V, i, n, rest, 0, f, 0); } if(*f == 1) return 0; return 1; }