gpt4 book ai didi

c++ - "Expected ' } ' at end of input"。为什么我不断收到此错误?

转载 作者:太空宇宙 更新时间:2023-11-04 14:00:58 25 4
gpt4 key购买 nike

我不是一个完全的新手,所以我明白它的意思等等,但我似乎无法弄清楚 Eclipse 似乎认为我缺少什么神秘的支架。

(请忽略我还没有构建我所说的我将在我的代码中构建的事实——我还没有走到那一步。)

#include "./BinaryTree.h"
using namespace ods;
typedef BTNode1 Node;
Node * buildNode(Node *p = NULL, Node *l = NULL, Node *r = NULL) {
Node * ans = new Node;
ans->parent = p; ans->left = l; ans->right = r;
return ans;
}

typedef BTNode1 Node;
Node * buildNodeComplete(Node *p = NULL, Node*l = NULL, Node *r = NULL) {
Node * ans = new Node;
ans->parent = p; ans->left = l; ans->right = r;
return ans;
}

typedef BTNode1 Node;
Node * buildNodeStringy(Node *p = NULL, Node*l = NULL, Node *r = NULL) {
Node * ans = new Node;
ans->parent = p; ans->left = l; ans->right = r;
return ans;
}

int main() {
// build random tree of 1023 nodes
BinaryTree<Node> T;
Node *u;
T.root() = buildNode();
int d;

for (int i = 1; i < 1023; ++i) {
T.randomWalk(u, d);
if (d == 0) u->left = buildNode(u);
else u->right = buildNode(u);
}

//build complete tree of 1023 nodes
BinaryTree<BTNode1> C;
Node *a;
C.root() = buildNodeComplete();
int g;

for (int i = 1; i <1023; i++) {
C.randomWalk(a, g);
if (g == 0) a->left = buildNodeComplete(a);
else a->right = buildNodeComplete(a);
}

//build stringy tree of 1023 nodes
BinaryTree<Node> S;
Node *q;
S.root() = buildNodeStringy();
int v;

for (int i = 1; i <1023; i++) {
S.randomWalk(q, v);
if (v == 0) q->left = buildNodeStringy(q);
else q->right = buildNodeStringy(q);
}

// measure random walks in T
double sum=0;
double sum1=0;
double sum2=0;
for (int i = 0; i < 1000; ++i) {
T.randomWalk(u, d);
sum += T.depth(u);
C.randomWalk(a, g);
sum1 += C.depth(a);
S.randomWalk(q, v);
sum2 += S.depth(q);
}

std::cout << "Average length of random walk through arbitrary tree is "
<< sum/1000;
std::cout << " and lg(n+1) = lg(1024) = 10."
<< std::endl;

//lab 5 part b
std::cout << "Average length of random walk through complete tree is "
<< sum1/1000 << endl;
std::cout << "Average length of random walk through stringy tree is "
<< sum2/1000;

return 0;
}

最佳答案

应该是this bug in Eclipse fixed , 但尝试在右括号后添加一个新行。过去需要在 .cpp 文件末尾有一个换行符,但现在实际上没有必要了。

此外,如果我曾经见过的话,这看起来像是一个数据结构类作业,祝你好运(在变得更容易之前会变得更难。)

关于c++ - "Expected ' } ' at end of input"。为什么我不断收到此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19307529/

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