void changeChild(struct Tree* T)
{
if(T->lchild || T->rchild)
{
changeChild(T->lchild);
changeChild(T->rchild);
struct Tree* temp = T->lchild;
T->lchild = T->rchild;
T->rchild = temp;
}
}
void PreOrderTraverse(int array[], int i, int len)
{
int pos = i;
int temp;
Stack S = InitStack();
while(pos<len || !EmptyStack())
{
if(pos<len)
{ //当结点存在时
printf("%d ", array[pos]->data);
push(&S, pos);
pos = 2*pos; //左孩子
}
else
{
temp = pop(&S);
pos = 2*temp + 1; //右孩子
}
}
}