2

这是我的 Node 类的简化版本:

class Node {
public:
    Node();

    // indicators of whether the node is a top or bottom node
    bool Top;
    bool Bot;

    // pointers for tree structure
    Node *Parent;
    Node *LeftC;
    Node *RightC;

    std::list<Node*> getNodesList();
};

我想要的是能够以特定顺序获得指向树中节点的指针列表。我尝试了以下代码来执行此操作:

std::list<Node*> Node::getNodesList(){
    if (Bot) return (std::list<Node*>(1,this));
    else {
        std::list<Node*> temp (1,this);
        temp.splice(temp.end(), LeftC->getNodesVector()); // Combine with left childrens
        temp.splice(temp.end(), RightC->getNodesVector()); // Combine with right childrens
        return temp;
    }
}

拼接功能不起作用并给我一个错误。

所以我的问题是:

  • 为什么拼接功能不能组合列表?
  • 有没有更有效的方法来返回指向节点的指针列表?
4

1 回答 1

1

由于我不知道您遇到的确切错误,因此只需快速浏览一下您的代码就可以告诉我您的Node类可能不知道是什么getNodesVector(),因为它没有在您的类中定义。

于 2013-07-25T17:49:05.697 回答