void OutputQueue(TQueue queue) { typename TQueue::key_map propertyMap = queue.keys(); // Read out the queue, saving the objects in the order they were in the queue while(!queue.empty()) { typename TQueue::value_type queuedObject = queue.top(); std::cout << "queuedObject: " << queuedObject << " "; typename boost::property_traits<typename TQueue::key_map>::value_type value = get(propertyMap, queuedObject); std::cout << " value: " << value << std::endl; queue.pop(); } }
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; }