void PostorderThreading (Tree * const ptree)
{
Node * previous = NULL ;
Postorder_Threading (ptree, &previous) ;
}
static void Postorder_Threading (Tree * const ptree, Node * * const previous)
{
if (*ptree != NULL)
{
Postorder_Threading (&(*ptree) -> left, previous) ;
Postorder_Threading (&(*ptree) -> right, previous) ;
if (NULL == (*ptree) -> left)
{
(*ptree) -> left_tag = THREAD ;
(*ptree) -> left = *previous ;
}
if (*previous != NULL)
if (NULL == (*previous) -> right)
{
(*previous) -> right_tag = THREAD ;
(*previous) -> right = *ptree ;
}
*previous = *ptree ;
}
}
void PostorderThreadedTraversal (const Tree tree, void (* pfun) (const Item item))
{
Node * scan = tree ;
while (LINK == scan -> left_tag)
scan = scan -> left ;
while (THREAD == scan -> right_tag)
{
(* pfun) (scan -> item) ;
scan = scan -> right ;
}
(* pfun) (scan -> item) ;
scan = FindMin (&tree -> right) ;
while (THREAD == scan -> right_tag)
{
(* pfun) (scan -> item) ;
scan = scan -> right ;
}
A_Recursive_Function_For_Postorder_Threaded (&tree, scan -> right) ;
}
static void A_Recursive_Function_For_Postorder_Threaded (const Tree * const ptree, const Node * const pnode)
{
if (*ptree != pnode)
{
A_Recursive_Function_For_Postorder_Threaded (&(*ptree) -> right, pnode) ;
printf ("%d ", (*ptree) -> item) ;
}
}