Ejemplo n.º 1
0
void AVL::breadFirstPrint(){
  TQueue<Node*> q;
  if(root_){
    q.enqueue(root_);
    while(!q.isEmpty()){
      Node* curr=q.front();
      q.dequeue();
      if(curr->left_)
        q.enqueue(curr->left_);
      if(curr->right_)
        q.enqueue(curr->right_);
      cout << curr->data_ << endl;
      
    }
  }
}
Ejemplo n.º 2
0
void TwoThreeTree::levelOrder() {
    if (root == NULL) return;

    // Use a tree to do levelOrder Traversal
    TQueue queue;
    queue.push(root);
    root->level = 0;

    cout << "Level Order Traversal:\n";

    int currentLevel = 0;
    while (!queue.isEmpty()) {
        const TNode *t = queue.top();
        
        if (t->level != currentLevel) {
            cout << endl;
            currentLevel = t->level;
        }
        
        // push t's children on queue, set their level nubmer
        t->print();
        if (!t->isLeaf) {
            int nextLevel = t->level + 1;
            t->left->level = nextLevel;
            queue.push(t->left);

            t->middle->level = nextLevel;
            queue.push(t->middle);

            if (t->rlow != -1) {
                t->right->level = nextLevel;
                queue.push(t->right);
            }
        }

        queue.pop();
    }
    cout << endl << endl;
}