modify-rbtree-again
This commit is contained in:
parent
995a6355bf
commit
a7494100e7
|
@ -58,12 +58,12 @@ TestRBTree用于验证红黑树的功能和正确性,下面是该程序的使用
|
|||
|
||||
根据默认关键字数组构建红黑树
|
||||
|
||||

|
||||
主机截图无法粘贴至虚拟机,运行结果见实验报告
|
||||
|
||||
根据键值查找结点,输出相关信息并删除,可以输入'Y'或'y'展示删除后的红黑树
|
||||
|
||||

|
||||
主机截图无法粘贴至虚拟机,运行结果见实验报告
|
||||
|
||||
到达空树,退出程序
|
||||
|
||||

|
||||
主机截图无法粘贴至虚拟机,运行结果见实验报告
|
||||
|
|
|
@ -20,7 +20,7 @@ static Type arr[] = {10, 40, 30, 60, 90, 70, 20, 50, 80,
|
|||
/*
|
||||
* 创建红黑树
|
||||
*/
|
||||
RBRoot* create_rbtree()
|
||||
RBRoot* createRbtree()
|
||||
{
|
||||
RBRoot *root = (RBRoot *)malloc(sizeof(RBRoot));
|
||||
root->node = NULL;
|
||||
|
@ -89,7 +89,7 @@ static Node* minimum(RBTree tree)
|
|||
return tree;
|
||||
}
|
||||
|
||||
int rbtree_minimum(RBRoot *root, int *val)
|
||||
int rbtreeMinimum(RBRoot *root, int *val)
|
||||
{
|
||||
Node *node;
|
||||
|
||||
|
@ -290,7 +290,7 @@ static void insert_node(RBRoot *root, Node *node)
|
|||
/*
|
||||
* 创建结点
|
||||
*/
|
||||
static Node* create_rbtree_node(Type key, Node *parent, Node *left_child, Node* right_child)
|
||||
static Node* createRbtree_node(Type key, Node *parent, Node *left_child, Node* right_child)
|
||||
{
|
||||
Node* p;
|
||||
|
||||
|
@ -313,7 +313,7 @@ int RBTreeInsert(RBRoot *root, Type key)
|
|||
Node *node;
|
||||
if (search(root->node, key) != NULL)
|
||||
return -1;
|
||||
if ((node=create_rbtree_node(key, NULL, NULL, NULL)) == NULL)
|
||||
if ((node=createRbtree_node(key, NULL, NULL, NULL)) == NULL)
|
||||
return -1;
|
||||
|
||||
insert_node(root, node);
|
||||
|
@ -508,7 +508,7 @@ static void rbtree_destroy(RBTree tree)
|
|||
free(tree);
|
||||
}
|
||||
|
||||
void destroy_rbtree(RBRoot *root)
|
||||
void destroyRbtree(RBRoot *root)
|
||||
{
|
||||
if (root != NULL)
|
||||
rbtree_destroy(root->node);
|
||||
|
@ -533,7 +533,7 @@ static void rbtree_print(RBTree tree, Type key, int direction)
|
|||
}
|
||||
}
|
||||
|
||||
void print_rbtree(RBRoot *root)
|
||||
void printRbtree(RBRoot *root)
|
||||
{
|
||||
if (root!=NULL && root->node!=NULL)
|
||||
rbtree_print(root->node, root->node->key, 0);
|
||||
|
@ -544,7 +544,7 @@ void print_rbtree(RBRoot *root)
|
|||
int main(void){
|
||||
int i, ret;
|
||||
char cmd;
|
||||
RBRoot *root = create_rbtree();
|
||||
RBRoot *root = createRbtree();
|
||||
|
||||
int length = sizeof(arr) / sizeof(arr[0]);
|
||||
printf("------------------------------------------------------------");
|
||||
|
@ -609,6 +609,6 @@ int main(void){
|
|||
|
||||
}
|
||||
|
||||
destroy_rbtree(root);
|
||||
destroyRbtree(root);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ typedef struct RBTreeType{
|
|||
}RBRoot;
|
||||
|
||||
// 创建红黑树,返回"红黑树的根"!
|
||||
RBRoot* create_rbtree();
|
||||
RBRoot* createRbtree();
|
||||
|
||||
// 销毁红黑树
|
||||
void destroy_rbtree(RBRoot *root);
|
||||
void destroyRbtree(RBRoot *root);
|
||||
|
||||
// 将结点插入到红黑树中。插入成功,返回0;失败返回-1。
|
||||
int RBTreeInsert(RBRoot *root, Type key);
|
||||
|
@ -33,7 +33,6 @@ int RBTreeInsert(RBRoot *root, Type key);
|
|||
void RBTreeDelete(RBRoot *root, Type key);
|
||||
|
||||
|
||||
|
||||
// 中序遍历"红黑树"
|
||||
void RBTreeTraversal(RBRoot *root);
|
||||
|
||||
|
@ -42,9 +41,9 @@ void RBTreeTraversal(RBRoot *root);
|
|||
int RBTreeSearch(RBRoot *root, Type key);
|
||||
|
||||
// 返回最小结点的值(存于val)(找到返回0,找不到返回-1)
|
||||
int rbtree_minimum(RBRoot *root, int *val);
|
||||
int rbtreeMinimum(RBRoot *root, int *val);
|
||||
|
||||
// 打印红黑树
|
||||
void print_rbtree(RBRoot *root);
|
||||
void printRbtree(RBRoot *root);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue