int main() { struct searchTree * t = initTree(); struct searchTree *root = t = treeInsert(t , 3); treeInsert(t , 8); struct searchTree * x = treeInsert(t , 4); struct searchTree * y = treeInsert(t , 14); treeInsert(t , 9); treeInsert(t , 2); treeInsert(t , 0); treeWalk(t); treeDelete(x); treeWalk(root); treeDelete(y); treeWalk(root); printf("\nmax = %d min = %d \n", treeMax(t) -> k, treeMin(t) -> k); if(treeSearch(t, 3) != NULL) printf("found\n"); printf("%d\n",t -> k); t = treeSuccessor(t); printf("%d\n",t -> k); t = treePredecessor(t); printf("%d\n",t -> k); }
bool traverse(BRNode * x, int k, int t) { if (x == NULL) { return false; } BRNode * y = x; while ((y = treePredecessor(y)) != NULL) { // [-1,2147483647], 1, 2147483647 should cause overflow if (abs(x->value - y->value) < 0 || abs(x->value - y->value) > t) { break; } if (abs(x->index - y->index) <= k) { return true; } } y = x; while ((y = treeSuccessor(y)) != NULL) { if (abs(x->value - y->value) < 0 || abs(x->value - y->value) > t) { break; } if (abs(x->index - y->index) <= k) { return true; } } return false; }