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


C++ TreeNode::GetRightSib方法代码示例

本文整理汇总了C++中TreeNode::GetRightSib方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeNode::GetRightSib方法的具体用法?C++ TreeNode::GetRightSib怎么用?C++ TreeNode::GetRightSib使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TreeNode的用法示例。


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

示例1: Z

/*----------------------------------------------------------------------------------------------------------------------
|   Randomly chooses a node to serve as node Z (the bottom of the three nodes involved in a Larget-Simon move). The
|   supplied node `middle' is the node serving as Y. In the figure below, the nodes labeled Z are all possible
|   candidates for the return value of this function. The node selected as Z should be the owner of the lowermost edge
|   involved in the move (X owns the uppermost edge and Y owns the middle edge).
|>
|	     X  X  X
|	      \ | /
|          \|/
|	  Z  Z  Y
|	   \ | /
|	    \|/
|	     Z
|	     |
|>
*/
TreeNode * LargetSimonMove::chooseZ(
  TreeNode * middle)    /**< is the middle node (Y) */
    {
    TreeNode * nd = NULL;
	TreeNode * U = middle->GetParent();
	PHYCAS_ASSERT(U != NULL);
	unsigned uchildren = U->CountChildren();
	unsigned which_child = rng->SampleUInt(uchildren);
	if (which_child == 0)
		{
		// Selected "child" is actually U's parent
		nd = U;
		}
	else
		{
		// Selected child is one of U's actual children (but cannot be equal to middle)
		unsigned k = 1;
		for (nd = U->GetLeftChild(); nd != NULL; nd = nd->GetRightSib())
			{
			if (nd == middle)
				continue;
			else
				{
				if (k == which_child)
					break;
				++k;
				}
			}
		PHYCAS_ASSERT(nd != NULL);
		}
    return nd;
    }
开发者ID:Linhua-Sun,项目名称:phycas,代码行数:48,代码来源:larget_simon_move.cpp

示例2: BuildStackFromNodeAndSiblings

/*----------------------------------------------------------------------------------------------------------------------
|	
*/
inline void effective_postorder_edge_iterator::BuildStackFromNodeAndSiblings(TreeNode * curr, const TreeNode * nodeToSkip)
	{
	// Handle case in which curr equals nodeToSkip
	if (nodeToSkip != NULL && curr == nodeToSkip)
		curr = curr->GetRightSib();
	if (curr == NULL)
		return;

	// Create a temporary stack of nodes to remember
	std::stack<TreeNode *> ndStack;

	// Visit all nodes in the subtree extending up from curr's parent (with the exception 
	// of the subtree whose root is nodeToSkip)
	for (;;)
		{
		TreeNode * par = curr->GetParent();
		if ((!isValidChecker.empty()) && isValidChecker(curr, par))
			{
			// edge was valid:
			//   - let curr be curr's next sibling
			curr = curr->GetRightSib();
			if (nodeToSkip != NULL && curr == nodeToSkip)
				curr = curr->GetRightSib();
			}
		else
			{
			// edge was not valid:
			//   - push edge onto edge stack
			//   - if curr has a sibling, push that sibling onto ndStack (i.e. remember it so we can deal with it later)
			//   - let curr be curr's left child
			edgeStack.push(EdgeEndpoints(curr, par));
			TreeNode * r = curr->GetRightSib();
			if (r != NULL && r == nodeToSkip)
				r = r->GetRightSib();
			if (r != NULL)
				ndStack.push(r);
			curr = curr->GetLeftChild();
			}

		if (curr == NULL)
			{
			// we've come to the end of the road for this subtree
			// let curr be node on top of ndStack
			if (ndStack.empty())
				break;
			curr = ndStack.top();
			ndStack.pop();
			}
		}
	}
开发者ID:danielfan,项目名称:Phycas,代码行数:53,代码来源:edge_iterators.hpp

示例3:

/*----------------------------------------------------------------------------------------------------------------------
|   Selects a child of the supplied `nd' at random from a discrete uniform distribution.
*/
TreeNode * LargetSimonMove::randomChild(
  TreeNode * nd)    /**< is the parent node whose children are candidates */
    {
	unsigned ychildren = nd->CountChildren();
	unsigned which_child = rng->SampleUInt(ychildren);
	unsigned k = 0;
    TreeNode * child = nd->GetLeftChild();
	for (; child != NULL; child = child->GetRightSib())
		{
		if (k == which_child)
			break;
		++k;
		}
	PHYCAS_ASSERT(child != NULL);
    return child;
    }
开发者ID:Linhua-Sun,项目名称:phycas,代码行数:19,代码来源:larget_simon_move.cpp


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