ADD file via upload
This commit is contained in:
parent
93d6fa60af
commit
3800f0e411
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file: test_rbtree.h
|
||||||
|
* @brief: a head file of red-black tree structure
|
||||||
|
* @version: 1.0
|
||||||
|
* @author: 全天星辰-何超
|
||||||
|
* @date: 2023/9/23
|
||||||
|
*/
|
||||||
|
#ifndef REDBLACKTREE_H_
|
||||||
|
#define REDBLACKTREE_H_
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// 红黑树节点结构体
|
||||||
|
typedef struct RBNode {
|
||||||
|
int key;
|
||||||
|
struct RBNode *left_child;
|
||||||
|
struct RBNode *right_child;
|
||||||
|
struct RBNode *parent;
|
||||||
|
bool is_red;
|
||||||
|
} RBNodeType;
|
||||||
|
|
||||||
|
// 红黑树结构体
|
||||||
|
typedef struct RBTree {
|
||||||
|
RBNodeType *root;
|
||||||
|
RBNodeType *leaf;
|
||||||
|
} RBTreeType;
|
||||||
|
|
||||||
|
// 函数声明
|
||||||
|
void InitializeRBTree(RBTreeType* tree);
|
||||||
|
void FreeRBTree(RBTreeType* tree, RBNodeType* node);
|
||||||
|
static RBNodeType* RBTreeMinimum(RBNodeType* node);
|
||||||
|
static void RBTreeTransplant(RBTreeType* tree, RBNodeType* old_node, RBNodeType* new_node);
|
||||||
|
void TestRBTree(void);//测试
|
||||||
|
static void RBTreeInorderTraversal(RBTreeType* tree, RBNodeType* node);
|
||||||
|
void RBTreeTraversal(RBTreeType *tree);
|
||||||
|
static void RBTreeLeftRotate(RBTreeType *tree, RBNodeType *current_node);
|
||||||
|
static void RBTreeRightRotate(RBTreeType *tree, RBNodeType* current_node);
|
||||||
|
static void InsertFixup(RBTreeType *tree, RBNodeType* current_node);
|
||||||
|
void RBTreeInsert(RBTreeType *tree, RBNodeType* new_node);
|
||||||
|
static void DeleteFixup(RBTreeType *tree, RBNodeType* current_node);
|
||||||
|
void RBTreeDelete(RBTreeType *tree, RBNodeType* target_node);
|
||||||
|
RBNodeType* FindSuccessor(RBTreeType *tree, RBNodeType* current_node);
|
||||||
|
RBNodeType* RBTreeSearch(RBTreeType *tree, int key);
|
||||||
|
#endif
|
Loading…
Reference in New Issue