我不是一个完整的新手,所以我明白这意味着什么等等,但我似乎无法弄清楚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;
}
答案 0 :(得分:0)
据说this bug in Eclipse fixed,但尝试在封闭的括号后面添加一个新行。过去需要在.cpp文件的末尾添加一个新行字符,但现在实际上并不是必需的。
此外,如果我见过一个,这看起来像是数据结构类的分配,所以好运(在它变得更容易之前变得更难。)