sargazi
یک شنبه 30 اردیبهشت 1386, 11:26 صبح
# define M100
Void inorder2 (node type *tree)
{
Struct stack
{
Int top;
Node type item [M];
}s;
Node type *p;
s.top = -1;
p=tree;
do{
// travel down left braches as far as possible
// saving pointers to nodes passed
While (p !=null)
{
Push (s,p)
P=p -> left;
}
// check if finished
If (!empty(s))
{
// at this point the left sub tree is empty
P=pop(s);
Printf ("%d", p -> info); // visit the root
P=p -> right; //traverse right sub tree
}
}while (! Empty(s) || p !=null );
}
Void inorder2 (node type *tree)
{
Struct stack
{
Int top;
Node type item [M];
}s;
Node type *p;
s.top = -1;
p=tree;
do{
// travel down left braches as far as possible
// saving pointers to nodes passed
While (p !=null)
{
Push (s,p)
P=p -> left;
}
// check if finished
If (!empty(s))
{
// at this point the left sub tree is empty
P=pop(s);
Printf ("%d", p -> info); // visit the root
P=p -> right; //traverse right sub tree
}
}while (! Empty(s) || p !=null );
}