先序遍历啊
int Num =0;
void PushStack(struct TreeNode* Stack[],struct TreeNode* p)
{
Stack[Num] =p;
Num++;
}
struct TreeNode* PopStack(struct TreeNode* Stack[])
{
struct TreeNode* Temp;
Temp = Stack[Num-1];
Num--;
return Temp;
}
void PreOrderBTree2(struct TreeNode* Tree)
{
struct TreeNode* Stack[Max];
struct TreeNode* p;
Num = 0;
p = Tree;
do
{
if( NULL !=p)
{
printf("%c ",p->Data);
PushStack(Stack,p);
p = p->Lsubtree;
}
else
{
p =PopStack(Stack);
p = p->Rsubtree;
}
}while(0!=Num ||p !=NULL);
}
这个是我写的,主要是要建立一个栈储存根节点,一直到输完左孩子,然后出栈,再进栈右孩子(如果有的话)之后再出栈