예제 #1
0
파일: bst.c 프로젝트: patrickmurrow/cosc242
void bst_preorder(bst b, void f(char *str)){
   if (b == NULL){
      return;
   }
   f(b->key);
   bst_preorder(b->left, f);
   bst_preorder(b->right, f);
}
예제 #2
0
int main(void) {
    bst b = bst_new();

    printf("inserting d,b,f,a,c,e,g\n");
    b = bst_insert(b, "d");
    b = bst_insert(b, "b");
    b = bst_insert(b, "f");
    b = bst_insert(b, "a");
    b = bst_insert(b, "c");
    b = bst_insert(b, "e");
    b = bst_insert(b, "g");

    printf("inorder traversal\n");
    bst_inorder(b, print_key);

    printf("preorder traversal\n");
    bst_preorder(b, print_key);

    printf("searching\n");
    dosearch(b, "f");
    dosearch(b, "o");
    dosearch(b, "x");
    dosearch(b, "e");
    dosearch(b, "d");
   
    bst_free(b);
    return EXIT_SUCCESS;
}
예제 #3
0
int main(){
  int i;

  int a[] = {8, 2, 7, 9, 11, 3, 2, 6};


  BST_PTR t = bst_create();

  for(i=0; i<8; i++)
    bst_insert(t, a[i]);

  assert(bst_size(t) == 7);

  test_insert(t);

  test_contains(t);

  bst_inorder(t);

  bst_preorder(t);

  bst_postorder(t);

  bst_ith_smallest(t, 1)

  bst_size(t);

  bst_free(t);
}
예제 #4
0
파일: test.c 프로젝트: jwill006/BST
void t_height() {
	int i;
    int a[] = {8, 2, 6, 9, 11, 3, 7};
	
    BST_PTR t = bst_create();
	BST_PTR t2;
	
    for(i=0; i<7; i++)
        bst_insert(t, a[i]);
	
	
	
	bst_remove(t,11);
	bst_remove(t,2);
	bst_preorder(t);
	printf("Min elem: %d\n", bst_min(t));
	printf("Max elem: %d\n", bst_max(t));
	
	printf("Nearest elem: %d\n", bst_get_nearest(t,500));
	printf("Num LEQ: %d\n", bst_num_leq(t,10));
	
	bst_free(t);
	
}