本文整理汇总了C++中NodeData::getCount方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeData::getCount方法的具体用法?C++ NodeData::getCount怎么用?C++ NodeData::getCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeData
的用法示例。
在下文中一共展示了NodeData::getCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recursiveCopy
/**
* @brief helper for copy-constructor
* @details recursively copy nodes from a tree pre-order
*
* @param origNode Node on the original tree to be copied over
*/
void TBST::recursiveCopy(Node* origNode) {
if(origNode != NULL) {
if(origNode->isLeaf()) {
NodeData* d = origNode->getData();
insert(d->getToken(), d->getCount());
d = NULL;
} else if(!origNode->hasLeftChild()) {
// 1: have right child, no left child
// copy the node
NodeData* d = origNode->getData();
insert(d->getToken(), d->getCount());
d = NULL;
// then recurse down and copy the right child
recursiveCopy(origNode->getRight());
} else if(!origNode->hasRightChild()) {
// 2: have left child, no right child
NodeData* d = origNode->getData();
insert(d->getToken(), d->getCount());
d = NULL;
// then recurse down and copy the left child
recursiveCopy(origNode->getLeft());
} else {
// 3: have children on both sides
NodeData* d = origNode->getData();
insert(d->getToken(), d->getCount());
d = NULL;
// then recurse down and copy both children
recursiveCopy(origNode->getLeft());
recursiveCopy(origNode->getRight());
}
}
}
示例2: testSetters
NodeData testSetters(NodeData& B) {
NodeData A("a");
A.decreaseCount();
assert(A.getCount() == 0);
int bCount = 7;
while(B.getCount() < bCount) {
B.increaseCount();
}
assert(B.getCount() == bCount);
assert(A.getToken() < B.getToken());
A = B;
assert(A.getToken() == B.getToken());
return B;
}
示例3: testConstructors
NodeData testConstructors() {
NodeData A;
assert(A.getToken() == "");
assert(A.getCount() == 1);
NodeData B("hello world");
assert(B.getToken() == "hello world");
NodeData C(B);
assert(C.getToken() == "hello world");
return B;
}
示例4: getMaxByFrequency
/**
* @brief Recursively query for max NodeDatas from left/right subtrees
* and compare.
* @details private recursive method. Compares maximum candidates from the root
* node, the left subtree, and the right subtree. O(n) running time.
*
* @param subroot Node pointer to the root of the subtree currently recursed on
* @return NodeData with maximum secondary value among the 3 candidates
*/
NodeData* TBST::getMaxByFrequency(Node* subroot) {
if(subroot != NULL) {
NodeData* maxData = subroot->getData(); // default max
NodeData* leftMax = NULL; NodeData* rightMax = NULL;
if(subroot->hasLeftChild())
leftMax = getMaxByFrequency(subroot->getLeft());
if(subroot->hasRightChild())
rightMax = getMaxByFrequency(subroot->getRight());
if(leftMax != NULL && maxData->getCount() < leftMax->getCount())
maxData = leftMax;
// break ties in favor of the right branch since we desire an
// increasing sort order
if(rightMax != NULL && maxData->getCount() <= rightMax->getCount())
maxData = rightMax;
return maxData;
}
else return NULL;
}
示例5: getMinByFrequency
/**
* @brief Recursively query for max NodeDatas from left/right subtrees
* and compare.
* @details private recursive method. Compares minimum candidates from the root
* node, the left subtree, and the right subtree. Runs in O(n) time.
*
* @param subroot Node pointer to the root of the subtree currently recursed on
* @return NodeData with minimum secondary value among the 3 candidates
*/
NodeData* TBST::getMinByFrequency(Node* subroot) {
if(subroot != NULL) {
NodeData* minData = subroot->getData(); // default min
NodeData* leftMin = NULL; NodeData* rightMin = NULL;
if(subroot->hasLeftChild())
leftMin = getMinByFrequency(subroot->getLeft());
if(subroot->hasRightChild())
rightMin = getMinByFrequency(subroot->getRight());
// break ties in favor of the node on the left since we want increasing
// sort order
if(leftMin != NULL && minData->getCount() >= leftMin->getCount()) {
minData = leftMin;
}
if(rightMin != NULL && minData->getCount() > rightMin->getCount()) {
minData = rightMin;
}
return minData;
}
else return NULL;
}
示例6: assert
/**
* @brief copy constructor
* @details creates a copy of the passed in TBST
*
* @param other TBST tree to copy
*/
TBST::TBST(const TBST& other) {
root = NULL;
nodeCount = 0;
if(other.root != NULL) {
// handle root separately
assert(root == NULL); // make sure that tree is empty
// then add the root
NodeData* rootData = other.root->getData();
insert(rootData->getToken(), rootData->getCount());
// recursively copy the left and right subtrees
recursiveCopy(other.root->getLeft());
recursiveCopy(other.root->getRight());
}
else {
root = NULL;
}
}