void PreorderThreading (Tree * const ptree) ; static void Preorder_Threading (Tree * const ptree, Node * * const previous) ; void PreorderThreadedTraversal (const Tree tree, void (* pfun) (const Item item)) ; void PreorderThreading (Tree * const ptree) { Node * previous = NULL ; Preorder_Threading (ptree, &previous) ; } static void Preorder_Threading (Tree * const ptree, Node * * const previous) { if (*ptree != NULL) { 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 ; if (NULL == (*previous) -> right && LINK == (*previous) -> right_tag) (*previous) -> right_tag = THREAD ; if (LINK == (*ptree) -> left_tag) Preorder_Threading (&(*ptree) -> left, previous) ; if (LINK == (*ptree) -> right_tag) Preorder_Threading (&(*ptree) -> right, previous) ; } } void PreorderThreadedTraversal (const Tree tree, void (* pfun) (const Item item)) { Node * scan = tree ; while (scan != NULL) { while (LINK == scan -> left_tag) { (* pfun) (scan -> item) ; scan = scan -> left ; } while (scan != NULL && THREAD == scan -> right_tag) { (* pfun) (scan -> item) ; scan = scan -> right ; } } }