set 与 map底层实现

news2024/9/22 17:19:09

目录

set与map底层基本介绍​

红黑树的迭代器

operator++

情况一:右不为空

情况二:右为空

operator--

情况一:end()--

情况二:左子树不为空

情况三:右子树不为空

项目代码

RBTree.h

myMap.h

mySet.h


set与map底层基本介绍

红黑树的迭代器

迭代器的好处是可以方便遍历,是数据结构的底层实现与用户透明。如果想要给红黑树增加迭代器,需要考虑以前问题:

begin()与end()

STL明确规定,begin()与end()代表的是一段前闭后开的区间,而对红黑树进行中序遍历后,可以得到一个有序的序列,因此:begin()可以放在红黑树中最小节点(即最左侧节点)的位置,end()放在最大节点(最右侧节点)的下一个位置,关键是最大节点的下一个位置在哪块?能否给成nullptr呢?答案是行不通的,因为对end()位置的迭代器进行--操作,必须要能找最后一个元素,此处就不行,因此最好的方式是将end()放在头结点的位置:

 

operator++

二叉搜索树的中序遍历是升序,如果对某一个数++,那么结果则是中序遍历的下一个数,那么我们如何根据一个值在红黑树当中找到它中序遍历的下一个值呢?

此时我们以局部看整体的思想

情况一:右不为空

情况二:右为空


 

    Self& operator++(){
        if(_node->_right){
            // 右不为空,右子树最左节点就是中序第一个
            Node* leftMost = _node->_right;
            while (leftMost->_left) {
                leftMost = leftMost->_left;
            }
            
            _node = leftMost;
        }else{
            // 右为空
            // 孩子是父亲左的那个祖先
            Node* cur = _node;
            Node* parent = cur->_parent;
            while (parent && cur == parent->_right)
            {
                cur = parent;
                parent = cur->_parent;
            }

                _node = parent;
            }
            return *this;
        }

operator--

情况一:end()--

情况二:左子树不为空

情况三:右子树不为空

    Self& operator--(){
        if(_node == nullptr)//end()
        {
            // --end(),特殊处理,走到中序最后一个节点,整棵树的最右节点
            Node* rightMost = _root;
            while(rightMost && rightMost->_right){
                rightMost = rightMost->_right;
            }
            _node = rightMost;
        }
        else if(_node->_left){
            // 左子树不为空,中序左子树最后一个
            Node* rightMost = _node->_left;
            while(rightMost->_right){
                rightMost = rightMost->_right;
            }
            _node = rightMost;
        }else{
            // 孩子是父亲右的那个祖先
            Node* cur = _node;
            Node* parent = cur->_parent;
            
            while(parent && parent->_left == cur){
                cur = parent;
                parent = parent->_parent;
            }
            _node = parent;
        }
        return *this;
    }
    
};

项目代码

RBTree.h

//
//  RBTree.h
//  红黑树
//
//  Created by 南毅 on 2024/7/22.
//
#include <iostream>
using namespace std;
#include <assert.h>
#include <vector>
#include <time.h>
#include <string.h>

enum Colour{
    RED,
    BLACK
};

template<class T>
struct RBTreeNode
{
    T _data;
    RBTreeNode<T>* _left;
    RBTreeNode<T>* _right;
    RBTreeNode<T>* _parent;
    Colour _col;

    RBTreeNode(const T& data)
        :_left(nullptr)
        , _right(nullptr)
        , _parent(nullptr)
        , _data(data)
        , _col(RED)
    {}
};

template<class T,class Ref, class Ptr>
struct RBTreeIterator {
    typedef RBTreeNode<T> Node;
    typedef RBTreeIterator<T,Ref,Ptr> Self;
    
    Node* _node;
    Node* _root;
    
    RBTreeIterator(Node* node,Node* root)
    :_node(node),
    _root(root)
    {
        
    }
    
    Ref operator*(){
        return _node->_data;
    }
    
    Ptr operator->(){
        return &_node->_data;
    }
    
    
    bool operator!=(const Self& s){
        return _node != s._node;
    }
    
    bool operator==(const Self& s){
        return _node == s._node;
    }
    
    Self& operator++(){
        if(_node->_right){
            // 右不为空,右子树最左节点就是中序第一个
            Node* leftMost = _node->_right;
            while (leftMost->_left) {
                leftMost = leftMost->_left;
            }
            
            _node = leftMost;
        }else{
            // 右为空
            // 孩子是父亲左的那个祖先
            Node* cur = _node;
            Node* parent = cur->_parent;
            while (parent && cur == parent->_right)
            {
                cur = parent;
                parent = cur->_parent;
            }

                _node = parent;
            }
            return *this;
        }
        
    Self& operator--(){
        if(_node == nullptr)//end()
        {
            // --end(),特殊处理,走到中序最后一个节点,整棵树的最右节点
            Node* rightMost = _root;
            while(rightMost && rightMost->_right){
                rightMost = rightMost->_right;
            }
            _node = rightMost;
        }
        else if(_node->_left){
            // 左子树不为空,中序左子树最后一个
            Node* rightMost = _node->_left;
            while(rightMost->_right){
                rightMost = rightMost->_right;
            }
            _node = rightMost;
        }else{
            // 孩子是父亲右的那个祖先
            Node* cur = _node;
            Node* parent = cur->_parent;
            
            while(parent && parent->_left == cur){
                cur = parent;
                parent = parent->_parent;
            }
            _node = parent;
        }
        return *this;
    }
    
};


template<class K, class T, class KeyOfT>
class RBTree
{
public:
    int _rotateNum = 0;
    typedef RBTreeIterator<T,T&,T*> Iterator;
    typedef RBTreeIterator<T,const T&,const T*> ConstIterator;
    
    Iterator Begin(){
        Node* leftMost = _root;
        while(leftMost && leftMost->_left){
            leftMost = leftMost->_left;
        }
        
        return Iterator(leftMost,_root);
    }
    
    
    Iterator End(){
        return Iterator(nullptr,_root);
    }
    
    ConstIterator Begin() const
    {
        Node* leftMost = _root;
        while(leftMost && leftMost->_left){
            leftMost = leftMost->_left;
        }
        
        return ConstIterator(leftMost,_root);
    }
    
    ConstIterator End() const
    {
        return ConstIterator(nullptr,_root);
    }
private:
    typedef RBTreeNode<T> Node;
    Node* _root = nullptr;
    
    void RotateL(Node* parent)
    {
        _rotateNum++;
        Node* subR = parent->_right;
        Node* subRL = subR->_left;

        parent->_right = subRL;
        if (subRL)
            subRL->_parent = parent;

        Node* parentParent = parent->_parent;

        subR->_left = parent;
        parent->_parent = subR;

        if (parentParent == nullptr)
        {
            _root = subR;
            subR->_parent = nullptr;
        }
        else
        {
            if (parent == parentParent->_left)
            {
                parentParent->_left = subR;
            }
            else
            {
                parentParent->_right = subR;
            }

            subR->_parent = parentParent;
        }
    }

    void  RotateR(Node* parent)
    {
        _rotateNum++;

        Node* subL = parent->_left;
        Node* subLR = subL->_right;

        parent->_left = subLR;
        if (subLR)
            subLR->_parent = parent;

        Node* parentParent = parent->_parent;

        subL->_right = parent;
        parent->_parent = subL;

        if (parentParent == nullptr)
        {
            _root = subL;
            subL->_parent = nullptr;
        }
        else
        {
            if (parent == parentParent->_left)
            {
                parentParent->_left = subL;
            }
            else
            {
                parentParent->_right = subL;
            }

            subL->_parent = parentParent;
        }

    }
    
    void Destroy(Node* root)
    {
        if (root == nullptr)
            return;

        Destroy(root->_left);
        Destroy(root->_right);
        delete root;
    }

    Node* Copy(Node* root)
    {
        if (root == nullptr)
            return nullptr;

        Node* newRoot = new Node(root->_kv);
        newRoot->_left = Copy(root->_left);
        newRoot->_right = Copy(root->_right);

        return newRoot;
    }
    
    bool Check(Node* root, int blackNum, const int refNum)
        {
            if (root == nullptr)
            {
                //cout << blackNum << endl;
                if (refNum != blackNum)
                {
                    cout << "存在黑色节点的数量不相等的路径" << endl;
                    return false;
                }

                return true;
            }

            if (root->_col == RED && root->_parent->_col == RED)
            {
                cout << root->_kv.first << "存在连续的红色节点" << endl;
                return false;
            }

            if (root->_col == BLACK)
            {
                blackNum++;
            }

            return Check(root->_left, blackNum, refNum)
                && Check(root->_right, blackNum, refNum);
        }

        int _Size(Node* root)
        {
            return root == nullptr ? 0 : _Size(root->_left) + _Size(root->_right) + 1;
        }

        int _Height(Node* root)
        {
            if (root == nullptr)
                return 0;

            int leftHeight = _Height(root->_left);
            int rightHeight = _Height(root->_right);

            return leftHeight > rightHeight ? leftHeight + 1 : rightHeight + 1;
        }

        void _InOrder(Node* root)
        {
            if (root == nullptr)
            {
                return;
            }

            _InOrder(root->_left);
            cout << root->_kv.first << ":" << root->_kv.second << endl;
            _InOrder(root->_right);
        }

public:
    RBTree() = default;

    RBTree(const RBTree& t)
    {
        _root = Copy(t._root);
    }

    RBTree& operator=(RBTree t)
    {
        swap(_root, t._root);
        return *this;
    }

    ~RBTree()
    {
        Destroy(_root);
        _root = nullptr;
    }
    
    pair<Iterator,bool> Insert(const T& data){
        // 树为空,插入节点为新根节点
        if(_root == nullptr){
            _root = new Node(data);
            _root->_col = BLACK;
            return make_pair(Iterator(_root,_root), true);
        }
        
        Node* parent = nullptr;
        Node* cur = _root;
        
        KeyOfT kot;
        
        //找到插入位置
        while (cur)
        {
            if (kot(cur->_data) < kot(data))
            {
                parent = cur;
                cur = cur->_right;
            }
            else if (kot(cur->_data) > kot(data))
            {
                parent = cur;
                cur = cur->_left;
            }
            else
            {
                return make_pair(Iterator(cur, _root), false);
            }
        }

        //新增节点。颜色给红色
        cur = new Node(data);
        Node* newnode = cur;
        cur->_col = RED;
        
        if (kot(parent->_data) < kot(data))
        {
            parent->_right = cur;
        }
        else
        {
            parent->_left = cur;
        }
        cur->_parent = parent;

        
        while(parent && parent->_col == RED){
            Node* grandfather = parent->_parent;
            //     g
            //  p     u
            if(parent == grandfather->_left){
                Node* uncle = grandfather->_right;
                if (uncle && uncle->_col == RED) {
                    //情况一 :叔叔存在且为红
                    //变色 + 继续往上处理 p u 变黑 g变红
                    parent->_col = uncle->_col = BLACK;
                    grandfather->_col = RED;
                    
                    cur = grandfather;
                    parent = cur->_parent;
                    
                }
                else{
                    //情况二:叔叔不存在或者存在为黑 --》旋转+变色
                    if(cur == parent->_left){
                        //    g
                        //  p   u
                        //c
                        //单旋:gpc一边高
                        RotateR(grandfather);
                        parent->_col = BLACK;
                        grandfather->_col = RED;
                    }else{
                        //    g
                        //  p   u
                        //    c
                        //双旋:pgc两段高
                        RotateL(parent);
                        RotateR(grandfather);
                        
                        cur->_col = BLACK;
                        grandfather->_col = RED;
                    }
                    
                    break;
                }
            }
            else{
                //    g
                //  u   p
                Node* uncle = grandfather->_left;
                // 叔叔存在且为红,-》变色即可
                if (uncle && uncle->_col == RED)
                {
                    parent->_col = uncle->_col = BLACK;
                    grandfather->_col = RED;
                    
                    // 继续往上处理
                    cur = grandfather;
                    parent = cur->_parent;
                }
                else // 叔叔不存在,或者存在且为黑
                {
                    // 情况二:叔叔不存在或者存在且为黑
                    // 旋转+变色
                    //      g
                    //   u     p
                    //            c
                    if (cur == parent->_right)
                    {
                        RotateL(grandfather);
                        parent->_col = BLACK;
                        grandfather->_col = RED;
                    }
                    else
                    {
                        //        g
                        //   u     p
                        //      c
                        RotateR(parent);
                        RotateL(grandfather);
                        cur->_col = BLACK;
                        grandfather->_col = RED;
                    }
                    break;
                }
                
            }
        }
        _root->_col = BLACK;
        return make_pair(Iterator(newnode, _root), true);

        
    }
    
    void InOrder()
    {
        _InOrder(_root);
        cout << endl;
    }

    int Height()
    {
        return _Height(_root);
    }

    int Size()
    {
        return _Size(_root);
    }

    bool IsBalance()
    {
        if (_root == nullptr)
            return true;

        if (_root->_col == RED)
        {
            return false;
        }
        
        // 参考值
        int refNum = 0;
        Node* cur = _root;
        while (cur)
        {
            if (cur->_col == BLACK)
            {
                ++refNum;
            }

            cur = cur->_left;
        }

        return Check(_root, 0, refNum);
    }

    Iterator Find(const K& key)
    {
        Node* cur = _root;
        while (cur)
        {
            if (cur->_kv.first < key)
            {
                cur = cur->_right;
            }
            else if (cur->_kv.first > key)
            {
                cur = cur->_left;
            }
            else
            {
                return Iterator(cur,_root);
            }
        }

        return End();
    }


};

myMap.h

//
//  myMap.h
//  set和map模拟实现
//
//  Created by 南毅 on 2024/7/23.
//

#include "RBTree.h"

namespace nanyi {
template<class K,class V>
class map{
    struct MapKeyOfT{
        const K& operator()(const pair<K,V>& kv){
            return kv.first;
        }
    };

    
public:
    typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::Iterator iterator;
        typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::ConstIterator const_iterator;

        iterator begin()
        {
            return _t.Begin();
        }

        iterator end()
        {
            return _t.End();
        }

        const_iterator begin() const
        {
            return _t.Begin();
        }

        const_iterator end() const
        {
            return _t.End();
        }

        pair<iterator, bool> insert(const pair<K, V>& kv)
        {
            return _t.Insert(kv);
        }

        iterator find(const K& key)
        {
            return _t.Find(key);
        }

        V& operator[](const K& key)
        {
            pair<iterator, bool> ret = insert(make_pair(key, V()));
            return ret.first->second;
        }

    private:
        RBTree<K, pair<const K, V>, MapKeyOfT> _t;
    };

    void test_map()
    {
        map<string, string> dict;
        dict.insert({ "sort", "排序" });
        dict.insert({ "left", "左边" });
        dict.insert({ "right", "右边" });

        dict["left"] = "左边,剩余";
        dict["insert"] = "插入";
        dict["string"];

        map<string, string>::iterator it = dict.begin();
        while (it != dict.end())
        {
            // 不能修改first,可以修改second
            //it->first += 'x';
            it->second += 'x';

            cout << it->first << ":" << it->second << endl;
            ++it;
        }
        cout << endl;
    }
};

mySet.h

//
//  mySet.h
//  set和map模拟实现
//
//  Created by 南毅 on 2024/7/23.
//


#include "RBTree.h"

namespace nanyi {
template<class K>
class set{
    struct SetKeyOfT{
        const K& operator()(const K& key){
            return key;
        }
    };
    
    RBTree<K, const K, SetKeyOfT> _t;
public:
    typedef typename RBTree<K, const K, SetKeyOfT>::Iterator iterator;
    typedef typename RBTree<K, const K, SetKeyOfT>::ConstIterator const_iterator;
    
    iterator begin(){
        return _t.Begin();
    }
    
    iterator end(){
        return _t.End();
    }
    
    const_iterator begin() const
    {
        return _t.Begin();
    }

    const_iterator end() const
    {
        return _t.End();
    }
    
    pair<iterator,bool> insert(const K& key){
        return _t.Insert(key);
    }
    
    iterator find(const K& key){
        return _t.Find(key);
    }
    
    void Print(const set<int>& s)
    {
        set<int>::const_iterator it = s.end();
        while (it != s.begin())
        {
            --it;
            //*it += 2;
            cout << *it << " ";
        }
        cout << endl;
    }

};

void Print(const set<int>& s)
{
    set<int>::const_iterator it = s.end();
    while (it != s.begin())
    {
        --it;
        //*it += 2;
        cout << *it << " ";
    }
    cout << endl;
}
void test_set()
{
    set<int> s;
    int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14 };
    for (auto e : a)
    {
        s.insert(e);
    }

    for (auto e : s)
    {
        cout << e << " ";
    }
    cout << endl;

    set<int>::iterator it = s.end();
    while (it != s.begin())
    {
        --it;

        cout << *it << " ";
    }
    cout << endl;

    it = s.begin();
    //*it += 10;
    while (it != s.end())
    {
        cout << *it << " ";
        ++it;
    }
    cout << endl;

    Print(s);
}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1944831.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

TCP的socket的API

关键的两个类 1)ServerSocket 该类专门给服务器用的,这个构造方法传入端口进行连接 accept相当于是接听操作,进行连接 close关闭当前套接字,当socket对象与进程的生命周期不一致时需要提前释放资源,就需要调用close 为什么UDP的客户端服务器中没有这个close方法,因为这个sock…

Manticore Search(es轻量级替代)

概念&#xff1a; Manticore Search 是一个使用 C 开发的高性能搜索引擎&#xff0c;创建于 2017 年&#xff0c;其前身是 Sphinx Search 。Manticore Search 充分利用了 Sphinx&#xff0c;显着改进了它的功能&#xff0c;修复了数百个错误&#xff0c;几乎完全重写了代码并保…

服务器数据恢复—Isilon存储集群节点误删除的数据恢复案例

Isilon存储结构&#xff1a; Isilon存储使用的是分布式文件系统OneFS。在Isilon存储集群里面每个节点均为单一的OneFS文件系统&#xff0c;所以Isilon存储在进行横向扩展的同时不会影响数据的正常使用。Isilon存储集群所有节点提供相同的功能&#xff0c;节点与节点之间没有主备…

国产大模型之光-Kimi AI

又是一年年中&#xff0c;各种工作总结、报告数不胜数&#xff0c;打工人们又面临年中绩效的考核&#xff0c;还恰逢毕业季&#xff0c;又有很多校招朋友初入职场&#xff0c;成为打工人&#xff0c;老板PUA&#xff0c;Mentor不带教&#xff0c;加班熬夜掉头发。 现在各大互联…

TCP系列(一)-介绍TCP

服务 TCP和UDP同样使用IP提供的服务&#xff0c;但是TCP提供的是面向连接&#xff0c;可靠的字节流服务 面向连接 使用TCP进行通信双方&#xff0c;必须先建立连接&#xff0c;然后进行数据交换 可靠服务 将应用数据分割成固定大小的报文段每次发出报文&#xff0c;会启动定时…

嵌入式单片机软件与硬件的结合方法分析

不知道大家有没有疑惑,为什么软件能控制硬件?关于这个问题,给出直观解释的文章:本文分析STM32单片机到底是如何软硬件结合的,分析单片机程序如何编译,运行。 软硬件结合 初学者,通常有一个困惑,就是为什么软件能控制硬件?就像当年的51,为什么只要写P1=0X55,就可以…

防近视台灯有效果吗?精选学生护眼台灯哪个品牌好

在当今快节奏的生活环境中&#xff0c;我们常常忽视了眼部休息&#xff0c;对眼睛的关爱变得尤为稀缺&#xff0c;这直接导致了近视率的逐年飙升。在这样的背景下&#xff0c;不少人将护眼需求投向防近视台灯。防近视台灯也称为护眼灯&#xff0c;护眼灯号称有独特的护眼技术&a…

spring 中的属性解析器 PropertyResolver

我们知道&#xff0c;在 spring 中可以使用占位符&#xff0c;格式如 "${}"&#xff0c;大括号中间放置待替换的占位符&#xff0c;待使用值时根据配置的属性解析器进行解析。但具体是如何操作的&#xff0c;且看本文来进行分析。 PropertyResolver 这是一个针对任…

Unity UGUI 之 图集

本文仅作学习笔记与交流&#xff0c;不作任何商业用途 本文包括但不限于unity官方手册&#xff0c;唐老狮&#xff0c;麦扣教程知识&#xff0c;引用会标记&#xff0c;如有不足还请斧正 本文在发布时间选用unity 2022.3.8稳定版本&#xff0c;请注意分别 1.什么是图集 精灵图…

recursion depth exceeded” error

有些时候不可以用jax.jit装饰器 参考资料&#xff1a;使用 JAX 后端在 Keras 3 中训练 GAN |由 Khawaja Abaid |中等 (medium.com)

最优化理论与方法-第十讲割平面法

文章目录 1. 原问题&#xff1a;2. 割平面法程序步骤2.1 第一次迭代2.2 第二次迭代2.3 第三次迭代 1. 原问题&#xff1a; 给定下列约束优化问题&#xff1a; ( P ) min ⁡ 3 x 1 2 2 x 2 2 s t . − 5 x 1 − 2 x 2 3 ≤ 0 , x ∈ X { x ∈ Z n ∣ 8 x 1 8 x 2 ≥ 1 , 0…

记事本案例组件版本(源码分享)

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 非常期待和您一起在这个小…

基于Hutool实现自定义模板引擎,实现json个性化模板引擎转换

文章目录 前言编写引擎类&#xff1a;JsonTemplateEngine编写模板类&#xff1a;CustomTemplate编写测试代码测试json文件测试类 前言 由于百度搜索json模板引擎&#xff0c;推荐的都是一些freemarker之类的&#xff0c;需要引入其他的依赖&#xff0c;而且在编写json模板的时…

深入浅出WebRTC—Pacer

平滑发包&#xff08;Pacer&#xff09;是 WebRTC 实现高质量实时通信不可或缺的一部分。在视频通信中&#xff0c;单帧视频可能包含大量的数据&#xff0c;如果未经控制地立即发送&#xff0c;可能瞬间对网络造成巨大压力。Pacer 能够根据网络条件动态调整发送速率&#xff0c…

springboot校园车辆管理系统-计算机毕业设计源码63557

校园车辆管理系统 摘 要 校园车辆管理系统是当前高校校园管理中的一个重要方面&#xff0c;其有效管理和调度对于提升校园的运行效率和管理水平至关重要。本论文基于Spring Boot框架开发了一套校园车辆管理系统&#xff0c;系统主要包括用户和管理员两大角色&#xff0c;涵盖…

pytest使用

主要技术内容 1.pytest设计 接口测试 框架设想 common—公共的东西封装 1.request请求 2.Session 3.断言 4.Log 5.全局变量 6.shell命令 ❖ config---配置文件及读取 ❖ Log— ❖ payload—请求参数—*.yaml及读取 ❖ testcases—conftest.py; testcase1.py…….可…

Chapter 14 Python数据容器总结

欢迎大家订阅【Python从入门到精通】专栏&#xff0c;一起探索Python的无限可能&#xff01; 文章目录 前言一、数据容器对比二、数据容器的通用操作【拓展】字符串大小比较 前言 Python 作为一种高级编程语言&#xff0c;内置了多种强大的数据容器&#xff0c;帮助开发者以更…

【GoLang】Golang 快速入门(第一篇)

目录 1.简介&#xff1a; 2.设计初衷&#xff1a; 3.Go语言的 特点 4.应用领域: 5.用go语言的公司&#xff1a; 6. 开发工具介绍以及环境搭建 1.工具介绍: 2.VSCode的安装: 3.安装过程&#xff1a; 4.Windows下搭建Go开发环境--安装和配置SDK 1.搭建Go开发环境 - 安装…

【洛谷】P1088 [NOIP2004 普及组] 火星人——C++

本题我们会用到函数next_permutation(start,end),是头文件algorithm标准库中的一个标准函数&#xff0c;用来表示[start,end]内存的数组中产生一个字典排序&#xff0c;比如[1 , 2 ,3]到[2 ,3, 1]再到[3 , 1, 2]这样的&#xff0c;这个函数的复杂度为&#xff08;n!&#xff09…

Rust代码答疑报错|Python一对一辅导答疑

Question 你好&#xff0c;我是悦创。 学员答疑&#xff1a; https://code.bornforthis.cn/?id4e72084d-1eaf-44ed-8067-744671491574https://code.bornforthis.cn/?id664ff169-41d6-409f-a05b-02ed42279759 问题代码&#xff1a; // You can bring module paths into sc…