• 二叉树


    建立空树

    void MakeEmpty(SearchTree T) {
        if ( T != NULL) {
            MakeEmpty(T->Left);
            MakeEmpty(T->Right);
            free(T);
        }
    }

    查找

    Position Find(ElementType X, SearchTree T) {
        if (T == NULL) 
            return NULL;
        if (X < T->Element)
            return Find(X, T->Left);
        else if (X > T->Element)
            return Find(x, T->Right);
        else
            return T;
    }

    最小值

    Position FindMin(SearchTree T) {
        if (T == NULL) {
            return NULL;
        }
        else if (T->Left == NULL) {
            return T;
        }
        else
            return FindMin(T-Left);
    }

    插入

    SearchTree Insert(ElementType X, SearchTree T) {
        if (T == NULL) {
            T == malloc(sizeof(struct TreeNode));
            if (T == NULL) {
                Error("out of space");
            }
            else {
                T->Element = X;
                T->Left = T-Right = NULL;
            }
        }
        else if (X < T->Element) {
            T->Left = Insert(X, T->Left);
        }
        else 
            T-Right = Insert(X, T->Right);
    
        return T;
    }

    删除

    SearchTree DeleteMin(ElementType X, SearchTree T) {
        Position TmpCell;
    
        if (T == NULL) {
            Error("Not found");
        }
        else if (X < T->Element)
            T->Left = Delete(X, T->Left);
        else if (X > T->Element)
            T-Right = Delete(X, T->Right);
        else if (T->Left && T->Right) {
            TmpCell = FindMin(T-Right);
            T->Element = TmpCell->Element;
            T->Right = Delete(T->Element, T->Right);
        }
        else {
            TmpCell = T;
            if (T->Left == NULL)
                T = T->Right;
            else if (R->Right == NULL)
                T = T->Left;
            free(TmpCell);
        }
        return T;
    }
  • 相关阅读:
    springboot+fegin实现负载均衡
    springcloud实现微服务服务注册、负载均衡
    spring boot服务状态监控+shell远程连接服务
    微服务基础概念及相关技术组件
    集群分布式基础概念及了解
    http第一章-telnet测试
    spring整合netty

    springMVC+spring+JPA配置文件
    CAN信号值解析
  • 原文地址:https://www.cnblogs.com/m2492565210/p/7258739.html
Copyright © 2020-2023  润新知