2013-10-10 8 views
1

我不是一個完整的新手,所以我明白它的意思,等等,但我似乎無法弄清楚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; 
} 
+8

檢查頭文件(太) –

+1

如果您建立你會看到錯誤的位置 –

+1

包含語句中的'。/'是多餘的;使用'#include'語句中的''''在缺省情況下首先搜索源文件的目錄。 –

回答

0

據稱this bug in Eclipse fixed,但嘗試添加新在封閉的圓括號之後。它曾經被要求在.cpp文件的末尾有一個新的行字符,但現在它並不是必須的。

而且,這看起來像一個數據結構,課堂作業,如果我見過一個,對這麼好運氣(它變得更難變得越來越容易了。)

相關問題