0

我正在使用队列来实现广度优先搜索。树的节点是state类型的,而队列中的节点是node类型的。

    struct node
{ 
 int b1,b2,b3,b4;
 node* link;
}

struct state
{
 int b1,b2,b3,b4;
 state* rightChild;
 state* leftChild;
};

Queue.enqueue() 函数的原型是:

     bool enqueue(node n);

要将树的节点(状态类型)传递给它,我必须通过复制构造函数或重载赋值运算符转换它们,或者-我可以使Queue成为状态的基类,以便状态对象在队列中被接受通过多态性。现在这样做的好方法是什么?

4

1 回答 1

0

How about using

struct node 
{
    struct state* treeNode;
    struct node* link;  
};

your queue can now simply store node* pointers

于 2012-08-24T13:45:18.360 回答