vector<vector<int> > levelOrderBottom(TreeNode *root) {
     vector<vector<int> > answer;
     if (root == NULL)
     {
         return answer;
     }
     queue<traverseNode> tmpQueue;
     traverseQueue.swap(tmpQueue);
     traverseQueue.push(traverseNode(root, 1));
     while(!traverseQueue.empty())
     {
         traverseNode topNode = traverseQueue.front();
         if (topNode.level > answer.size())
         {
             vector<int> emptyVector;
             answer.push_back(emptyVector);
         }
         answer[topNode.level - 1].push_back(topNode.node->val);
         traverseQueue.pop();
         if (topNode.node -> left != NULL)
         {
             traverseQueue.push(traverseNode(topNode.node->left, topNode.level + 1));
         }
         if (topNode.node -> right != NULL)
         {
             traverseQueue.push(traverseNode(topNode.node->right, topNode.level + 1));
         }
     }
     for (int i = 0; i < (answer.size()/2); i++)
     {
         answer[i].swap(answer[answer.size() - i - 1]);
     }
     return answer;
 }
Exemplo n.º 2
0
void traverseNode(Node* n)
{
  if (n != NULL) {
    traverseNode(n->d);
    printf("+%s\n",n->str);
    traverseNode(n->r);
  }
}
Exemplo n.º 3
0
void traverseNode(Node* n)
{
  if(n != NULL){
    traverseNode(n->l);
//     printf("n : %p n->l : %p n->r : %p %s \n",n,n->l,n->r,n->s);
    printf("+%s",n->s);
    traverseNode(n->r);
  }
}
Exemplo n.º 4
0
void TCBinaryObjectTree::traverseNode(TCBinaryObjectTreeNode *node,
									  TCTraversalFunc traversalFunc)
{
	if (node)
	{
		traverseNode(node->left, traversalFunc);
		traversalFunc(node->key, node->value);
		traverseNode(node->right, traversalFunc);
	}
}
Exemplo n.º 5
0
void traverseNode(Node* n)
{
  if(n != NULL)
  {
    traverseNode(n->l);
    printf("n : %p n->l : %p n->r : %p n->p : %p +%s%d %d\n",n,n->l,n->r,n->p,n->str,n->i,n->count);
//     printf("+%s%d ",n->str,n->i);
    traverseNode(n->r);
  }
}
Exemplo n.º 6
0
void traverse(Tree* tp)
{
  if(!isEmpty(tp))
  {
    traverseNode(tp->root);
  }
}
Exemplo n.º 7
0
Node* ComposedShadowTreeWalker::traverseLightChildren(const Node* node, TraversalDirection direction)
{
    ASSERT(node);
    if (Node* child = (direction == TraversalDirectionForward ? node->firstChild() : node->lastChild()))
        return traverseNode(child, direction);
    return 0;
}
Exemplo n.º 8
0
void traverse(BTree* btp)
{
  if(btp->root != NULL)
  {
    traverseNode(btp->root);
  }
}
Node* ComposedShadowTreeWalker::traverseSiblings(const Node* node, TraversalDirection direction)
{
    for (const Node* sibling = node; sibling; sibling = (direction == TraversalDirectionForward ? sibling->nextSibling() : sibling->previousSibling())) {
        if (Node* found = traverseNode(sibling, direction))
            return found;
    }
    return 0;
}
Node* ComposedShadowTreeWalker::traverseDistributedNodes(const Node* node, const InsertionPoint* insertionPoint, TraversalDirection direction)
{
    for (const Node* next = node; next; next = (direction == TraversalDirectionForward ? insertionPoint->nextTo(next) : insertionPoint->previousTo(next))) {
        if (Node* found = traverseNode(next, direction))
            return found;
    }
    return 0;
}
Exemplo n.º 11
0
Node* ComposedShadowTreeWalker::traverseSiblingInCurrentTree(const Node* node, TraversalDirection direction)
{
    ASSERT(node);
    if (Node* next = (direction == TraversalDirectionForward ? node->nextSibling() : node->previousSibling()))
        return traverseNode(next, direction);
    if (Node* next = traverseSiblingOrBackToYoungerShadowRoot(node, direction))
        return next;
    return escapeFallbackContentElement(node, direction);
}
Exemplo n.º 12
0
void ParseXML::parseXmlString(const QString &xmlStr)
{    
    this->doc.setContent(xmlStr);
    // docElement now refers to the node "xml"
    QDomElement docElem = this->doc.documentElement();
    traverseNode(docElem);
    //
    emit this->finished(true);
}
Exemplo n.º 13
0
// traverse node
bool Bvh::traverseNode( const Bvh_Node* node , const Ray& ray , Intersection* intersect , float fmin , float fmax ) const
{
	if( fmin < 0.0f )
		return false;

	if( intersect && intersect->t < fmin )
		return true;
	
    if( node->pri_num != 0 ){
        unsigned _start = node->pri_offset;
        unsigned _tri = node->pri_num;
        unsigned _end = _start + _tri;
        
        bool inter = false;
        for( unsigned i = _start ; i < _end ; i++ ){
            inter |= m_bvhpri[i].primitive->GetIntersect( ray , intersect );
            if( intersect == 0 && inter )
                return true;
        }
        return inter;
	}

    const Bvh_Node* left = node->left;
	const Bvh_Node* right = node->right;

	float	_fmin0 , _fmax0;
	_fmin0 = Intersect( ray , left->bbox , &_fmax0 );
	float	_fmin1 , _fmax1;
	_fmin1 = Intersect( ray , right->bbox , &_fmax1 );

	bool inter = false;
	if( _fmin1 > _fmin0 ){
		inter |= traverseNode( left , ray , intersect , _fmin0 , _fmax0 );
		if( inter && intersect == 0 ) return true;
		inter |= traverseNode( right , ray , intersect , _fmin1 , _fmax1 );
	}else{
		inter |= traverseNode( right , ray , intersect , _fmin1 , _fmax1 );
		if( inter && intersect == 0 ) return true;
		inter |= traverseNode( left , ray , intersect , _fmin0 , _fmax0 );
	}
	if( intersect == 0 )
		return inter;
	return true;
}
Exemplo n.º 14
0
/**
 * Traverses the "right boundary" of this range and
 * operates on each "boundary node" according to the
 * how parameter.  It is a-priori assumed
 * by this method that the right boundary does
 * not contain the range's start container.
 *
 * A "right boundary" is best visualized by thinking
 * of a sample tree:
 *                 A
 *                /|\
 *               / | \
 *              /  |  \
 *             B   C   D
 *            /|\     /|\
 *           E F G   H I J
 *
 * Imagine first a range that begins between the
 * "E" and "F" nodes and ends between the
 * "I" and "J" nodes.  The start container is
 * "B" and the end container is "D".  Given this setup,
 * the following applies:
 *
 * Partially Selected Nodes: B, D<br>
 * Fully Selected Nodes: F, G, C, H, I
 *
 * The "right boundary" is the highest subtree node
 * that contains the ending container.  The root of
 * this subtree is always partially selected.
 *
 * In this example, the nodes that are traversed
 * as "right boundary" nodes are: H, I, and D.
 *
 */
DOM_Node RangeImpl::traverseRightBoundary( DOM_Node root, int how )
{
    DOM_Node next = getSelectedNode( fEndContainer, fEndOffset-1 );
    bool isFullySelected = ( next!=fEndContainer );

    if ( next==root )
        return traverseNode( next, isFullySelected, false, how );

    DOM_Node parent = next.getParentNode();
    DOM_Node clonedParent = traverseNode( parent, false, false, how );

    while( parent!=null )
    {
        while( next!=null )
        {
            DOM_Node prevSibling = next.getPreviousSibling();
            DOM_Node clonedChild =
                traverseNode( next, isFullySelected, false, how );
            if ( how!=DELETE_CONTENTS )
            {
                clonedParent.insertBefore(
                    clonedChild,
                    clonedParent.getFirstChild()
                );
            }
            isFullySelected = true;
            next = prevSibling;
        }
        if ( parent==root )
            return clonedParent;

        next = parent.getPreviousSibling();
        parent = parent.getParentNode();
        DOM_Node clonedGrandParent = traverseNode( parent, false, false, how );
        if ( how!=DELETE_CONTENTS )
            clonedGrandParent.appendChild( clonedParent );
        clonedParent = clonedGrandParent;

    }

    // should never occur
    return null;
}
Exemplo n.º 15
0
void traverse(Heap* hp)
{
  if(hp->root != NULL)
  {
    traverseNode(hp->root);
  }
  else
  {
    printf("heap is empty\n");
  }
}
Exemplo n.º 16
0
Node* ComposedShadowTreeWalker::traverseNode(const Node* node, TraversalDirection direction)
{
    ASSERT(node);
    if (!isInsertionPoint(node))
        return const_cast<Node*>(node);
    const InsertionPoint* insertionPoint = toInsertionPoint(node);
    if (!insertionPoint->isActive())
        return const_cast<Node*>(node);
    if (Node* next = (direction == TraversalDirectionForward ? insertionPoint->first() : insertionPoint->last()))
        return traverseNode(next, direction);
    return traverseLightChildren(node, direction);
}
Exemplo n.º 17
0
/** Recursively traverses the children of a node.
 * 
 * This functionality is implemented as a separate function, as opposed to 
 * incorporating it directly into <i>paint</i>, because some nodes need to 
 * traverse their children at different times.
 * 
 * @param node Pointer to the parent node.
 */
void Traverser::traverseChildren(Node *node) {
	
	Node::iterator it;
	
	// Stop if sealed
	if (!node->areChildrenTraversable())
		return;
	
	// Traverse each child
	for (it=node->begin(); it!=node->end(); ++it) {
		traverseNode(*it);
	}
}
Exemplo n.º 18
0
Node* ComposedShadowTreeWalker::traverseSiblingOrBackToInsertionPoint(const Node* node, TraversalDirection direction)
{
    ASSERT(node);
    ElementShadow* shadow = shadowOfParent(node);
    if (!shadow)
        return traverseSiblingInCurrentTree(node, direction);
    InsertionPoint* insertionPoint = shadow->insertionPointFor(node);
    if (!insertionPoint)
        return traverseSiblingInCurrentTree(node, direction);
    if (Node* next = (direction == TraversalDirectionForward ? insertionPoint->nextTo(node) : insertionPoint->previousTo(node)))
        return traverseNode(next, direction);
    return traverseSiblingOrBackToInsertionPoint(insertionPoint, direction);
}
Exemplo n.º 19
0
/**
 * Traverses the "left boundary" of this range and
 * operates on each "boundary node" according to the
 * how parameter.  It is a-priori assumed
 * by this method that the left boundary does
 * not contain the range's end container.
 *
 * A "left boundary" is best visualized by thinking
 * of a sample tree:
 *
 *                 A
 *                /|\
 *               / | \
 *              /  |  \
 *             B   C   D
 *            /|\     /|\
 *           E F G   H I J
 *
 * Imagine first a range that begins between the
 * "E" and "F" nodes and ends between the
 * "I" and "J" nodes.  The start container is
 * "B" and the end container is "D".  Given this setup,
 * the following applies:
 *
 * Partially Selected Nodes: B, D<br>
 * Fully Selected Nodes: F, G, C, H, I
 *
 * The "left boundary" is the highest subtree node
 * that contains the starting container.  The root of
 * this subtree is always partially selected.
 *
 * In this example, the nodes that are traversed
 * as "left boundary" nodes are: F, G, and B.
 *
 */
DOM_Node RangeImpl::traverseLeftBoundary( DOM_Node root, int how )
{
    DOM_Node next = getSelectedNode( getStartContainer(), getStartOffset() );
    bool isFullySelected = ( next!=getStartContainer() );

    if ( next==root )
        return traverseNode( next, isFullySelected, true, how );

    DOM_Node parent = next.getParentNode();
    DOM_Node clonedParent = traverseNode( parent, false, true, how );

    while( parent!=null )
    {
        while( next!=null )
        {
            DOM_Node nextSibling = next.getNextSibling();
            DOM_Node clonedChild =
                traverseNode( next, isFullySelected, true, how );
            if ( how!=DELETE_CONTENTS )
                clonedParent.appendChild(clonedChild);
            isFullySelected = true;
            next = nextSibling;
        }
        if ( parent==root )
            return clonedParent;

        next = parent.getNextSibling();
        parent = parent.getParentNode();
        DOM_Node clonedGrandParent = traverseNode( parent, false, true, how );
        if ( how!=DELETE_CONTENTS )
            clonedGrandParent.appendChild( clonedParent );
        clonedParent = clonedGrandParent;

    }

    // should never occur
    return null;

}
Exemplo n.º 20
0
PERSON * findMemberByPhone(STRING phone)
{
    personList.memberCnt = 0;
    matchString = phone;
    traverseNode(rootNode, getMemberListByPhone);

    if (personList.memberCnt == 0)
        return NULL;
    else if (personList.memberCnt == 1)
        return personList.member[0];
    else
        return choiceDuplicatedOne(personList);
}
Exemplo n.º 21
0
static void traverseNode(TidyNode node, int level)
{
	TidyNode child;

/* first the callback function */
	(*traverse_tidycall) (node, level, true);

/* and now the children */
	for (child = tidyGetChild(node); child; child = tidyGetNext(child))
		traverseNode(child, level + 1);

	(*traverse_tidycall) (node, level, false);
}				/* traverseNode */
Exemplo n.º 22
0
// get the intersection between the ray and the primitive set
bool Bvh::GetIntersect( const Ray& ray , Intersection* intersect ) const
{
	float fmax;
	float fmin = Intersect( ray , m_bbox , &fmax );
	if( fmin < 0.0f )
		return false;

	if( traverseNode( m_root , ray , intersect , fmin , fmax ) ){
		if( intersect == 0 )
			return true;
		return intersect->primitive != 0 ;
	}
    
	return false;
}
void Node::depthFirstTraversal()
{
    traverseNode();

    if( 0 == childrenList.size() )
    {
        return ;
    }
    else
    {
        for( unsigned int i = 0 ; i < childrenList.size() ; ++i )
        {
            (childrenList[i])->depthFirstTraversal();
        }

        glPopMatrix();
    }
}
void TraversalNeighborGen::traverseNode(Visitor *v, TraversalData &td)
{
	if (!v->onNode(td))
		return;

	// stop if all leaves
	if (!td.node.data)
		return;

	// get children (in standard orientation)
	TraversalData ch[2][2][2];

	for (int i = 0; i < 8; i++)
	{
		const int x = i&1;
		const int y = (i>>1)&1;
		const int z = (i>>2)&1;
		genNodeChild(ch[x][y][z], td, x, y, z);
	}

	traverseNode(v, ch[0][0][0]);
	traverseNode(v, ch[0][1][0]);
	traverseNode(v, ch[1][0][0]);
	traverseNode(v, ch[1][1][0]);
	traverseNode(v, ch[0][0][1]);
	traverseNode(v, ch[0][1][1]);
	traverseNode(v, ch[1][0][1]);
	traverseNode(v, ch[1][1][1]);

	recFace0(v, ch);
	recFace1(v, ch);
	recFace2(v, ch);

	recEdge0(v, ch);
	recEdge1(v, ch);
	recEdge2(v, ch);

	traverseVertex(v, ch);
}
Exemplo n.º 25
0
void TestModel::load(const QByteArray data)
{
    if (data.isEmpty()) {
        return;
    }

    clear();

    QByteArray d(QByteArray::fromBase64(data));
    QDomDocument domDoc;

    QString error;
    int errLine = -1;

    if(domDoc.setContent(d, &error, &errLine)) {
        QDomElement domElement= domDoc.documentElement();
        traverseNode(domElement);
    } else {
//        qDebug() << "Error while QDomDocument::setContent :" << error << "line: " << errLine;
    }
}
void TraversalNeighborGen::traverse(OctTree &tree, Visitor *v)
{
	TraversalData td;
	td.node = tree.root;

	td.depth = 0;
	td.value = 0;
	td.isCopy = false;

	td.cellsize = 1 << (g.maxDepth+1);
	td.x = td.y = td.z = 0;

	static unsigned char root_neighborCells = 0;
	td.neighborCells = &root_neighborCells;

	static float blur_val = 0;
	td.blur_val = &blur_val;

	td.pt_num = 10000;

	traverseNode(v, td);
}
Exemplo n.º 27
0
void TCBinaryObjectTree::traverseTree(TCTraversalFunc traversalFunc)
{
	traverseNode(rootNode, traversalFunc);
}
Exemplo n.º 28
0
static void traverseTidy(void)
{
	traverseNode(tidyGetRoot(tdoc), 0);
}
Exemplo n.º 29
0
PERSONLIST getMemberList()
{
    personList.memberCnt = 0;
    traverseNode(rootNode, getMemberListByAll);
    return personList;
}
Exemplo n.º 30
0
void Traverser::start() {
	
	traverseNode(scene->getRoot());
}