Take the 2-minute tour ×
class Node
    int x,y;
    Node *left, *right;
    Node(int x, int y);

How do I make a deque using this?

deque<Node> balBinaryTree;

gives me errors

syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'


---edit--- also should I do

  deque<Node> balBinaryTree;


  deque<Node*> balBinaryTree;
share|improve this question
What error does it give you? –  SirPentor May 23 '12 at 17:05
both deque<Node> and deque<Node*> are correct. If you use the first one, a copy of the Node object you push_back in the deque will be added at the end of container. You should keep that in mind. –  qdii May 23 '12 at 17:14
add comment

2 Answers

up vote 2 down vote accepted
#include <deque>
std::deque<Node> balBinaryTree;

also should I do

deque<Node> balBinaryTree; or

deque<Node*> balBinaryTree;

You should decide it yourself. deque<Node> leads to unnecessary copying. deque<Node*> leads to possible memory management problems.

share|improve this answer
did you include <deque> ? –  qdii May 23 '12 at 17:07
already did it =) –  inkooboo May 23 '12 at 17:08
add comment
#include <deque>
#include <memory>
std::deque<std::shared_ptr<Node>> balBinaryTree;

This takes care of the memory management for you and means you wont have to worry about the memory management explicitly.

Note: you are using naked pointers in your Node, so be careful and make sure the lifetime of the objects outlast the raw pointers so you don't leak.

share|improve this answer
add comment

Your Answer


