Topics
/****
"Title" assumes the addition of a flag field to the nodes of a three-strand list
(Mark takes a value of 0, 1, or 2) to distinguish it from reaching that node during the traversal.
You should continue to the left or right or access the node. Try to store the knot
The non-recursive sequential traversal algorithm of two-fork tree without stack-assist is programmed.
Cross-linked list type definition with flag field:
typedef struct TRITNODE {
Telemtype data;
struct Tritnode *lchild, *rchild, *parent;
int mark; Flag field
} Tritnode, *tritree;
* * * *Find the first node that the subtree begins to traverse, that is, the node in the bottom-left corner of the entire tree accesses the node that the entire subtree accesses first. Back to the parent node, the right node of the parent node is the second-visited node. If the parent node does not have a right subtree, or if the right subtree has already been accessed, it accesses itself and returns to the previous parent node. By the above has been determined that the parent node has a right subtree, then re-guide his right sub-tree. Code
void postorder (Tritree T, Void (*visit) (Telemtype))/* Do not use the stack, non-recursive sequential traversal of the binary tree T, */* For each node of the element domain data call
Function Visit */{Tritree p,pr;
p = T;
while (p) {if (p->lchild)//Find the node at the bottom-most left corner p = p->lchild;
else {if (p->rchild)//If the node in the lower-left corner has a right node P = p->rchild; else {visit (p->data);
Access the first node to be accessed P->mark = 1; p = p->parent; Returns the parent node while (p && (p->rchild = = NULL | | p->rchild->mark = = 1))//If the right node has been accessed or not
There is a right node {visit (p->data);
P->mark = 1;
p = p->parent;
if (p)//through the above loop, determine that the current node must contain the right node, access the right subtree P = p->rchild; }
}
}
}