mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-07-03 15:56:52 +08:00
实测发现删除6的时候,parent指向错误
This commit is contained in:
parent
9a3a3f84a8
commit
49b8c92ad1
4
mk.bat
4
mk.bat
@ -1,8 +1,8 @@
|
||||
@REM D:\Lang\cmake-3.27.5-windows-x86_64\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=D:\Software\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=D:\Software\mingw64\bin\g++.exe -SF:/OpenDemo/1_vsc_cmake -Bf:/OpenDemo/1_vsc_cmake/build -G "MinGW Makefiles"
|
||||
@REM cmake -Bbuild -G "Visual Studio 17 2022"
|
||||
|
||||
@REM cmake -B build -G "MinGW Makefiles"
|
||||
cmake -B build -G "Unix Makefiles"
|
||||
cmake -B build -G "MinGW Makefiles"
|
||||
@REM cmake -B build -G "Unix Makefiles"
|
||||
|
||||
make -C build
|
||||
make -C build install
|
||||
|
17
src/tree.c
17
src/tree.c
@ -1541,7 +1541,8 @@ static bool tree_avl_rebalance(struct _tree* self, struct _tree_node* root)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
self->print_obj(root->obj);
|
||||
|
||||
// self->print_obj(root->obj);
|
||||
tree_set_balance(self, root);
|
||||
int balance = root->balance;
|
||||
if(balance == 2)
|
||||
@ -1778,12 +1779,16 @@ static bool tree_avl_delete_double_child(struct _tree* self, struct _tree_node*
|
||||
assert(self != NULL);
|
||||
assert(node != NULL);
|
||||
struct _tree_node* tmp = self->find_min(self, node->right);
|
||||
if(tmp == NULL)
|
||||
if(tmp != NULL)
|
||||
{
|
||||
return false;
|
||||
memmove(node->obj, tmp->obj, self->_obj_size);
|
||||
if(tmp->right != NULL)
|
||||
{
|
||||
node->right = tmp->right;
|
||||
tmp->right->parent = node;
|
||||
}
|
||||
tree_avl_delete_single_child(self, tmp);
|
||||
}
|
||||
memmove(node->obj, tmp->obj, self->_obj_size);
|
||||
tree_avl_delete_single_child(self, tmp);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1803,6 +1808,8 @@ bool tree_avl_delete(struct _tree* self, void* obj)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// debug
|
||||
self->print_obj(obj);
|
||||
|
||||
if(node->left != NULL && node->right != NULL)
|
||||
{
|
||||
|
@ -298,9 +298,9 @@ void test_tree_num(void)
|
||||
{
|
||||
tree->insert(tree, &data[i]);
|
||||
|
||||
printf("----- preorder -----\n");
|
||||
tree->preorder(tree, tree->_root);
|
||||
printf("\n");
|
||||
// printf("----- preorder -----\n");
|
||||
// tree->preorder(tree, tree->_root);
|
||||
// printf("\n");
|
||||
}
|
||||
printf("----- preorder -----\n");
|
||||
tree->preorder(tree, tree->_root);
|
||||
@ -355,10 +355,10 @@ void test_tree_num(void)
|
||||
|
||||
tree->delete(tree, &temp);
|
||||
|
||||
printf("----- breadth -----\n");
|
||||
tree->breadth(tree, tree->_root);
|
||||
printf("----- inorder -----\n");
|
||||
tree->inorder(tree, tree->_root);
|
||||
// printf("----- breadth -----\n");
|
||||
// tree->breadth(tree, tree->_root);
|
||||
printf("----- preorder -----\n");
|
||||
tree->preorder(tree, tree->_root);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user