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


C++ BinaryNode类代码示例

本文整理汇总了C++中BinaryNode的典型用法代码示例。如果您正苦于以下问题:C++ BinaryNode类的具体用法?C++ BinaryNode怎么用?C++ BinaryNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BinaryNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

long long BinaryTree::nodeCounts() {
    std::queue<BinaryNode*> collections;

    // Find first leaf and push it to stack
    collections.push(root_);
    long long count = 1;

    // Iterate the cell from root to its childrens to destory
    // binary tree
    BinaryNode* cell = NULL;
    while (!collections.empty())
    {
        cell = collections.front();
        collections.pop();

        // Push the children to stack
        if (!cell->isLeaf()) {
            BinaryNode *leftChild = cell->leftChild();
            BinaryNode *rightChild = cell->rightChild();
            if (leftChild != NULL) collections.push(leftChild);
            if (rightChild != NULL) collections.push(rightChild);
        }

        // Count the current node
        count++;
    }

    return count;
}
开发者ID:caomw,项目名称:LocalSlidePoisson,代码行数:29,代码来源:BinaryTree.cpp

示例2: unserializeItemNode_OTMM

bool Container::unserializeItemNode_OTMM(const IOMap& maphandle, BinaryNode* node)
{
	bool ret = Item::unserializeAttributes_OTMM(maphandle, node);

	if(ret) {
		BinaryNode* child = node->getChild();
		if(child) do {
			uint8_t type;
			if(!child->getByte(type)) {
				return false;
			}
			//load container items
			if(type == OTMM_ITEM) {
				Item* item = Item::Create_OTMM(maphandle, child);
				if(!item) {
					return false;
				}
				if(!item->unserializeItemNode_OTMM(maphandle, child)) {
					delete item;
					return false;
				}
				contents.push_back(item);
			} else {
				// corrupted file data!
				return false;
			}
		} while(child->advance());
		return true;
	}
	return false;
}
开发者ID:mattyx14,项目名称:rme,代码行数:31,代码来源:iomap_otmm.cpp

示例3: while

BinaryNode<T> *BST<T>::find_max(BinaryNode<T> *node) {

	// 	Keep going down rhs until rhs == NULL. Then return the node
	BinaryNode<T> *tmp = node;

	while (tmp->get_rhs() != NULL){
		tmp = tmp->get_rhs();
	}

	return tmp;



	// 	THIS IS ALL COMMENTED OUT TEMPORARILY BECAUSE OF ISSUES WITH ACCESSING THE NODES IN TREE
	// 	if (root != NULL){
	// 		BinaryNode<T> * entire_fucking_tree;
	// 		entire_fucking_tree = root;
	// 		root = NULL;
	// 		return entire_fucking_tree;
	// 	}
	// 		

	// TODO: Implement this function
	throw 1;
	// TODO: Implement this function (when you have a use for it)
	return NULL;
}
开发者ID:GoodGuySteve,项目名称:SchoolProjects,代码行数:27,代码来源:bst.cpp

示例4: 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

示例5: copyTree

 BinaryNode<ItemType>* copyTree(const BinaryNode<ItemType>* treePtr) const {
     BinaryNode<ItemType>* newTreePtr = nullptr;
     if (treePtr != nullptr) {
         newTreePtr = new BinaryNode<ItemType>(treePtr->getItem(), nullptr, nullptr);
         newTreePtr->setLeftChildPtr(copyTree(treePtr->getLeftChildPtr()));
         newTreePtr->setRightChildPtr(copyTree(treePtr->getRightChildPtr()));
     }
     return newTreePtr;
 }
开发者ID:etzelm,项目名称:Binary-Search-Tree-Implementation,代码行数:9,代码来源:assignment11.cpp

示例6: throw

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

示例7: eval

double Division::eval() const
{
  BinaryNode* p;
  p = dynamic_cast<BinaryNode*>(owner_);
  if (p == 0)
  {
    std::cerr << "this cannot happen" << std::endl;
    exit(1);
  } 
  return p->getLeft() / p->getRight();
}
开发者ID:dideler,项目名称:school-projects,代码行数:11,代码来源:ex6.4a.division.cpp

示例8:

BinaryNode<ItemType>* BinaryNodeTree<ItemType>::copyTree(const BinaryNode<ItemType>* treePtr) const
{
   BinaryNode<ItemType>* newTreePtr = nullptr;
   
   // Copy tree nodes during a preorder traversal
   if (treePtr != nullptr)
   {
      // Copy node
	   newTreePtr = new BinaryNode<ItemType>(treePtr->getItem(), nullptr, nullptr);
	   newTreePtr->setLeftChildPtr(copyTree(treePtr->getLeftChildPtr()));
      newTreePtr->setRightChildPtr(copyTree(treePtr->getRightChildPtr()));
   }  // end if
   
   return newTreePtr;
}  // end copyTree
开发者ID:kylienic,项目名称:CTP-250,代码行数:15,代码来源:BinaryNodeTree.cpp

示例9: BinaryNode

BinaryNode* BinaryTree::copyTree(const BinaryNode* nodePtr)
{
    if (nodePtr == 0)
    {
        return 0;
    }
    
    else
    {
        // make a new node
        BinaryNode* newNode = new BinaryNode(nodePtr->getWebsite());
        newNode->setLeftPtr(copyTree(nodePtr->getLeftPtr()));
        newNode->setRightPtr(copyTree(nodePtr->getRightPtr()));
        return newNode;
    }
}
开发者ID:DestinyCookie,项目名称:TeamProject-10,代码行数:16,代码来源:BinaryTree.cpp

示例10: sort

void BinaryHeap::sort(){
    
    BinaryNode* currentNode = last;
    
    // Sift the item up so long as it has a parent (not root)
    // and is greater than it's parent.
    while(currentNode->hasParent()){
        if(*currentNode > *currentNode->parent){
            int temp = currentNode->data;
            currentNode->setData(currentNode->parent->data);
            currentNode->parent->setData(temp);
            currentNode = currentNode->parent;
        }
        else{
            currentNode = root;
        }
    }
}
开发者ID:balajinandhu,项目名称:School-Projects-Assignments,代码行数:18,代码来源:BinaryHeap.cpp

示例11: printd

int BinaryNode::substr(BinaryNode& b, qore_offset_t offset) const {
   printd(5, "BinaryNode::substr(offset: "QSD") this: %p len: "QSD")\n", offset, this, len);

   checkOffset(offset);
   if (offset == (qore_offset_t)len)
      return -1;

   b.append((char*)ptr + offset, len - offset);
   return 0;
}
开发者ID:qorelanguage,项目名称:qore,代码行数:10,代码来源:BinaryNode.cpp

示例12: setLast

void BinaryHeap::setLast(){
    if(!last){
        BinaryNode* currentNode = root;
        
        // While our node has children we will check
        // to see if it has a right branch. If it doesn't
        // we will set to the left (which it must have).
        while(currentNode->hasChildren()){
            if(currentNode->hasRightChild()){
                currentNode = currentNode->rightChild;
            }
            else{
                currentNode = currentNode->leftChild;
            }
        }
        
        // We've reached a node with no children, our last element.
        last = currentNode;
    }
}
开发者ID:balajinandhu,项目名称:School-Projects-Assignments,代码行数:20,代码来源:BinaryHeap.cpp

示例13: f

ClientVersionID IOMapOTMM::getVersionInfo(const FileName& filename)
{
	wxString wpath = filename.GetFullPath();
	DiskNodeFileReadHandle f((const char*)wpath.mb_str(wxConvUTF8));
	if(f.isOk() == false) {
		return CLIENT_VERSION_NONE;
	}

	BinaryNode* root = f.getRootNode();
	if(!root) {return CLIENT_VERSION_NONE;}
	root->skip(1); // Skip the type byte

	uint16_t u16;
	uint32_t u32;

	if(!root->getU32(u32) || u32 != 1) { // Version
		return CLIENT_VERSION_NONE;
	}

	root->getU16(u16);
	root->getU16(u16);
	root->getU32(u32);

	if(root->getU32(u32)) { // OTB minor version
		return ClientVersionID(u32);
	}
	return CLIENT_VERSION_NONE;
}
开发者ID:mattyx14,项目名称:rme,代码行数:28,代码来源:iomap_otmm.cpp

示例14: getRightChildPtr

void BST::deleteMin()
{
	
	if (rootPtr->getLeftChildPtr()==nullptr && rootPtr->getRightChildPtr()!=nullptr)
	{
		BinaryNode* toDelete = rootPtr-> getRightChildPtr();
		rootPtr = rootPtr-> getRightChildPtr();
		delete toDelete;
	}
	else if (rootPtr->getLeftChildPtr()==nullptr)
	{
		delete rootPtr;
	}
	else
	{
		BinaryNode* parent = rootPtr;
		BinaryNode* child = rootPtr->getLeftChildPtr();
		while (child->getLeftChildPtr()!=nullptr)
		{
			child = child->getLeftChildPtr();
			parent = parent->getLeftChildPtr();
		}
		
		delete child;
		parent->setLeftChildPtr(nullptr);
	}
}
开发者ID:youngliu323,项目名称:EECS_560,代码行数:27,代码来源:BST.cpp

示例15:

T BST<T>::remove_root() {

	if (root == NULL) throw 3; //no root

	T retData = root->get_data();
	T maxData;
	BinaryNode<T>* tmpNode;

	if (root->get_lhs() == NULL){
		BinaryNode<T> *tmpRoot = root;
		root = root->get_rhs();
		delete tmpRoot;
		return retData;
	}

	tmpNode = find_max(root->get_lhs());
	maxData = tmpNode->get_data();
	if(remove(maxData) != maxData) throw 2; //removed the wrong data
	root->set_data(maxData);
	return retData;

	throw 1;
}
开发者ID:GoodGuySteve,项目名称:SchoolProjects,代码行数:23,代码来源:bst.cpp


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