hello,
I'm trying to create a IntervalTree : public Tree { }; Node is a nested class of Tree; I hope this code will be clear; I have some question about it. Beyond the fact that it create a ultra-not-balanced tree (I don't remember how these trees are called...maybe they are a name); but the questions aren't on the tree structure but other:
Qt Code:
  1. IntervalTree::IntervalTree(vector<Interval>& vec) : Tree() {
  2. vector<Interval>::iterator it;
  3. //createRoot( new Node(vec[0]) );
  4. Tree::Node* r = 0;
  5. int i=0;
  6. for (it = vec.begin(); it != vec.end(); ++it) {
  7. if ( r == 0) { createRoot( new Node( *it ) ); r = getRoot(); continue; }//1
  8. i %=2;
  9. if (i == 0) {
  10. r->setLeft( new Tree::Node( *it ) );
  11. r = r->getLeft();
  12. }
  13. else if (i == 1) {
  14. r->setRight( new Tree::Node( *it ) );
  15. r = r->getRight();
  16. }
  17. ++i;
  18. }
  19. }
To copy to clipboard, switch view to plain text mode 
Is good the use of setLeft() and right() and the line //1 ? Any simple suggest ?
Maybe was better put the createRoot in the call of Tree() at begin?