当前位置: 首页>>代码示例>>C++>>正文


C++ BinaryNode::getItem方法代码示例

本文整理汇总了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
开发者ID:kylienic,项目名称:CTP-250,代码行数:31,代码来源:BinaryNodeTree.cpp

示例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
开发者ID:kylienic,项目名称:CTP-250,代码行数:10,代码来源:BinaryNodeTree.cpp

示例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;
         }
     }
 }
开发者ID:etzelm,项目名称:Binary-Search-Tree-Implementation,代码行数:24,代码来源:assignment11.cpp

示例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();
 }
开发者ID:etzelm,项目名称:Binary-Search-Tree-Implementation,代码行数:5,代码来源:assignment11.cpp

示例5: getRootData

 ItemType getRootData() const {
     if (isEmpty()) cout << "PrecondViolatedExcep - getRootData() called with empty tree.\n";
     return rootPtr->getItem();
 }
开发者ID:etzelm,项目名称:Binary-Search-Tree-Implementation,代码行数:4,代码来源:assignment11.cpp


注:本文中的BinaryNode::getItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。