gpt4 book ai didi

c++ - 每个节点有两条边的有向图的实现 - 递归搜索功能

转载 作者:行者123 更新时间:2023-11-28 03:21:49 25 4
gpt4 key购买 nike

<分区>

我开始研究结构,我创建了一个我称之为LR的结构:

struct LR{
int v;
LR* L;
LR* R;
};

我了解如何以通用方式操作它 - 下面 main 中的代码,在我开始构建类之前,我已经开始编写递归函数,该函数采用 LR 中节点的“地址”以字符串(“LRLRR”)的形式返回所需的 LR,但我仍然从编译器中得到错误:

LR.cpp In function 'LR chooseNode(LR*, std::string)':    
LR.cpp [Error] request for member 'L' in 'tree', which is of pointer type 'LR*'

(也许你打算使用'->'?) - 错误部分与递归 chooseNode(*tree.L,str2);

我做错了什么或者更确切地说如何调试它? (除了我的实现的整个概念,这是相当练习)。

#include<iostream>
#include<string>
#define SHOW(a) std::cout << #a << ": " << (a) << std::endl
using namespace std;
struct LR{
int v;
LR* L;
LR* R;
};

LR chooseNode(LR* tree, string str){// for example str="LRL"

// for clarity I've cutted the most of the code

if(str[0]=='L')
chooseNode(*tree.L,str2);
else if(str[0]=='R')
chooseNode(*tree.R,str2);

};


int main(){

LR d1,d2,d3;
d1.v=4;
d1.L=&d2;
(*(d1.L)).L=&d3;
d3.v=12345;
SHOW((*(*d1.L).L).v);


cout<<"Opis: "<<"\n";
SHOW(int(&d1));
SHOW(int(&d2));
SHOW(sizeof(d2.v));

return (0);
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com