示例#1
0
void test_must_insert_small_data_on_left_side_of_root(){
	int data[] = {20,10};
	
	ASSERT(SUCCESS == insertInBST(tree,&data[0]));
	ASSERT(SUCCESS == insertInBST(tree,&data[1]));
	ASSERT(SUCCESS == searchInBST(tree,&data[1]));
}
示例#2
0
void test_must_insert_large_data_on_right_side_of_root(){
	int data[] = {5,10};
	
	ASSERT(SUCCESS == insertInBST(tree,&data[0]));
	ASSERT(SUCCESS == insertInBST(tree,&data[1]));
	ASSERT(SUCCESS == searchInBST(tree,&data[1]));
}
示例#3
0
void test_deletion_of_right_leaf_node(){
	int data[] = {10,20,30};
	
	insertInBST(tree,&data[0]);
	insertInBST(tree,&data[1]);
	insertInBST(tree,&data[2]);
	ASSERT(SUCCESS == deleteFromBST(tree,&data[2]));
	ASSERT(FAILURE == searchInBST(tree,&data[2]));
}
示例#4
0
void test_must_insert_data_at_second_level_on_left_side(){
	int data[] = {30,20,10};
	
	insertInBST(tree,&data[0]);
	insertInBST(tree,&data[1]);
	insertInBST(tree,&data[2]);
	ASSERT(SUCCESS == searchInBST(tree,&data[0]));
	ASSERT(SUCCESS == searchInBST(tree,&data[1]));
	ASSERT(SUCCESS == searchInBST(tree,&data[2]));
}
示例#5
0
node insertInBST(node tree, book newb){
    if(tree==NULL){
        tree = createNode(newb);
        tree->left = tree->right = NULL;
    }
    else if(tree->b->acc < newb->acc){
        tree->right = insertInBST(tree->right, newb);
    }
    else
        tree->left = insertInBST(tree->left, newb);

    return tree;
}
示例#6
0
int main(){
    book b = {10, "I2A", "Cormen", 720};
    book b1 = {5, "AA", "KM", 0};    
    book b2 = {7, "A2A", "K2M", 360};
    book b3 = {50, "CP", "DR", 200};
    book b4 = {100, "SM", "RK", 210};
    book b5 = {9, "SM", "RK", 210};
    book b6 = {90, "SM", "RK", 210};

    node tree1 = NULL;
    node binT = insertInBST(tree1, &b);
    binT = insertInBST(binT, &b1);
    binT = insertInBST(binT, &b2);
    binT = insertInBST(binT, &b3);    
    binT = insertInBST(binT, &b4);
    
    // printf("tree1:\n");
    // treePrint(binT);

    printf("\n");
    
    node tree2 = NULL;
    node binT2 = insertInBST(tree2, &b);
    binT2 = insertInBST(binT2, &b1);
    binT2 = insertInBST(binT2, &b2);
    binT2 = insertInBST(binT2, &b3);    
    binT2 = insertInBST(binT2, &b4);
    // binT2 = insertInBST(binT2, &b5);
    // binT2 = insertInBST(binT2, &b6);
    printf("\nbeforedel\ttree2:\n");
    book* maxPrice = findMaxPricedBook(binT2);
    printf("%s written by %s has maximum price, which is %d \n",maxPrice->title, maxPrice->name, maxPrice->price);
    treePrint(binT2);
    deleteNode(binT2, &b2);    
    deleteNode(binT2, &b3); 
    printf("\nafterdel\ttree2:\n");
    treePrint(binT2);
    printf("\n");
    
    printf("\nTest for not found case, should return 0 for not found, returned: %d \n",findNode(binT2, &b4));
    printf("Test for found case, should return 1 for  found, returned: %d \n",findNode(binT2, &b1));
    // node x = searchNode(binT2, &b);
    // printf("Search Node b: %d, %s, %s, %d\n", x->b->acc, x->b->title, x->b->name, x->b->price);

    return 0;
}
示例#7
0
void test_must_not_delete_data_that_not_exist(){
	int data = 5,elementToDelete = 10;
	insertInBST(tree,&data);
	ASSERT(FAILURE == deleteFromBST(tree,&elementToDelete));
}
示例#8
0
void test_must_delete_root_data(){
	int data = 5;
	insertInBST(tree,&data);
	ASSERT(SUCCESS == deleteFromBST(tree,&data));
	ASSERT(FAILURE == searchInBST(tree,&data));
}
示例#9
0
void test_must_not_search_element_if_not_present(){
	int searchElement = 10;
	int data = 5;
	ASSERT(SUCCESS == insertInBST(tree,&data));
	ASSERT(FAILURE == searchInBST(tree,&searchElement));
}
示例#10
0
void test_must_insert_root_data(){
	int data = 5;
	ASSERT(SUCCESS == insertInBST(tree,&data));
	ASSERT(SUCCESS == searchInBST(tree,&data));
}