///////////////////////////////////////////////////////////////////
// Recursive Dynamic Nodes //
///////////////////////////////////////////////////////////////////
InorderTraversal1(NodePtr Tree)
{
if(Tree != NULL)
{
InorderTraversal1(Tree->Left);
printf("%d\n",Tree->Info) // Visit Node
InorderTraversal1(Tree->Right);
}
}
///////////////////////////////////////////////////////////////////
// Stack - Dynamic Nodes //
///////////////////////////////////////////////////////////////////
#define MAXSTACK 10
struct Stack
{
int
Top;
NodePtr
Info[MAXSTACK];
};
InorderTraversal2(NodePtr Tree)
{
Stack
S;
NodePtr P;
S.Top = -1;
P = Tree;
do
{
//travel down Lefts as far as possible, saving past ptrs
while(P != NULL)
{
Push(S,P);
P = P->Left;
}
if(!Empty(S))
{
//here , the Left subTree is Empty
P = Pop(S);
printf("%d\n", P->Info); // Visit Node
P = P->Right;
}
}while(!Empty(S) && P != NULL);
}
///////////////////////////////////////////////////////////////////
// Right In-Threaded Dynamic Nodes //
///////////////////////////////////////////////////////////////////
InorderTraversal3 (NodePtr Tree)
{
NodePtr
P = Tree,
Q;
do
{
Q = NULL;
while(P != NULL) // Traverse Left branch
{
Q = P;
P = P->Left;
}
if(Q != NULL)
{
printf("%d\n", Q->Info); // Visit Node
P = Q->Right;
while(Q->rthread && P != NULL)
{
printf("%d\n", P->Info)
Q = P;
P = P->Right;
}
}
} while(Q != NULL);
}
///////////////////////////////////////////////////////////////////
// Right In-Threaded Static Array Of Nodes //
///////////////////////////////////////////////////////////////////
InorderTraversal4 (int Tree)
{
int
P = Tree,
Q;
do // Travel down Left links keeping Q behind P
{
Q = 0;
while (P != 0)
{
Q = P;
P = node[P].Left;
}
if (Q != 0)
{
printf("%d\n", node[Q].Info); // Visit Node
P = node[Q].Right;
while (P < 0)
{
Q = -P
printf("%d\n", node[Q].Right)
P = node[Q].Right;
}
} // Ttraverse Right subTree
} while(Q != 0);
}
///////////////////////////////////////////////////////////////////
// Father, Left, & Right Pointers In Nodes //
///////////////////////////////////////////////////////////////////
InorderTraversal5(NodePtr Tree)
{
NodePtr
P = Tree,
Q = NULL;
do
{
while(P != NULL)
{
Q = P;
P = P->Left;
}
if(Q != NULL)
{
printf("%d\n", Q->Info); // Visit Node
P = Q->Right;
}
while(Q != NULL && P == NULL)
{
do // Node(Q) has no Right son. back up till a
{ // Left son or the Tree root is encountered
P = Q;
Q = P->father;
} while(!isLeft(P) && Q != NULL);
if(Q != NULL)
{
printf("%d\n", Q->Info);
P = Q->Right;
}
}
} while(Q != NULL)
}