/// Traverse the tree (depth-first) until we come to the node with the index /// specified by 'index'. Return NULL if cur != index. GANodeBASE * _GATreeTraverse(unsigned int index, unsigned int & cur, GANodeBASE * node) { if(!node) { return (GANodeBASE *)0; } if(cur == index) { return node; } cur++; GANodeBASE * n; if((n = _GATreeTraverse(index, cur, node->child)) != (GANodeBASE *)0) { return n; } for(GANodeBASE * tmp = node->next; tmp && tmp != node; tmp = tmp->next) { if(cur == index) { return tmp; } cur++; if((n = _GATreeTraverse(index, cur, tmp->child)) != (GANodeBASE *)0) { return n; } } return (GANodeBASE *)0; }
// Set the current node to the node indexed by the integer x. If x is out of // bounds, we return NULL and don't change the state of the iterator. This // method uses a depth-first traversal to find the node. Root node is 0, then // we go up from there. GANodeBASE * GATreeIterBASE::warp(unsigned int x) { unsigned int w=0; GANodeBASE * tmp = _GATreeTraverse(x, w, root()); if(tmp) node = tmp; return(tmp); }