本文整理汇总了C++中BinaryNode::getItem方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryNode::getItem方法的具体用法?C++ BinaryNode::getItem怎么用?C++ BinaryNode::getItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryNode
的用法示例。
在下文中一共展示了BinaryNode::getItem方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getHeightHelper
BinaryNode<ItemType>* BinaryNodeTree<ItemType>::moveValuesUpTree(BinaryNode<ItemType>* subTreePtr)
{
BinaryNode<ItemType>* leftPtr = subTreePtr->getLeftChildPtr();
BinaryNode<ItemType>* rightPtr = subTreePtr->getRightChildPtr();
int leftHeight = getHeightHelper(leftPtr);
int rightHeight = getHeightHelper(rightPtr);
if (leftHeight > rightHeight)
{
subTreePtr->setItem(leftPtr->getItem());
leftPtr = moveValuesUpTree(leftPtr);
subTreePtr->setLeftChildPtr(leftPtr);
return subTreePtr;
}
else
{
if (rightPtr != nullptr)
{
subTreePtr->setItem(rightPtr->getItem());
rightPtr =moveValuesUpTree(rightPtr);
subTreePtr->setRightChildPtr(rightPtr);
return subTreePtr;
}
else
{
//this was a leaf!
// value not important
delete subTreePtr;
return nullptr;
} // end if
} // end if
} // end moveValuesUpTree
示例2: NotFoundException
ItemType BinaryNodeTree<ItemType>::getEntry(const ItemType& anEntry) const throw(NotFoundException)
{
bool isSuccessful = false;
BinaryNode<ItemType>* binaryNodePtr = findNode(rootPtr, anEntry, isSuccessful);
if (isSuccessful)
return binaryNodePtr->getItem();
else
throw NotFoundException("Entry not found in tree!");
} // end getEntry
示例3: moveValuesUpTree
BinaryNode<ItemType>* moveValuesUpTree(BinaryNode<ItemType>* subTreePtr) {
BinaryNode<ItemType>* leftPtr = subTreePtr->getLeftChildPtr();
BinaryNode<ItemType>* rightPtr = subTreePtr->getRightChildPtr();
int leftHeight = getHeightHelper(leftPtr);
int rightHeight = getHeightHelper(rightPtr);
if (leftHeight > rightHeight) {
subTreePtr->setItem(leftPtr->getItem());
leftPtr = moveValuesUpTree(leftPtr);
subTreePtr->setLeftChildPtr(leftPtr);
return subTreePtr;
}
else {
if (rightPtr != nullptr) {
subTreePtr->setItem(rightPtr->getItem());
rightPtr =moveValuesUpTree(rightPtr);
subTreePtr->setRightChildPtr(rightPtr);
return subTreePtr;
}
else {
delete subTreePtr;
return nullptr;
}
}
}
示例4: getEntry
ItemType getEntry(const ItemType& anEntry) const {
BinaryNode<ItemType>* nodeWithEntry = findNode(rootPtr, anEntry);
if (nodeWithEntry == nullptr) cout << "NotFoundException - Entry not found in tree.\n";
else return nodeWithEntry->getItem();
}
示例5: getRootData
ItemType getRootData() const {
if (isEmpty()) cout << "PrecondViolatedExcep - getRootData() called with empty tree.\n";
return rootPtr->getItem();
}