问题描述:将二叉树的两个孩子换位置,即左变右,右变左。不能用递规
代码:
typedef struct HaTree
{
int data;
struct HaTree *lChild, *rChild;
}HaTree;
void HaReverTree (HaTree *head)
{
int sum = -1;
HaTree* st[100];
if (head == NULL)
return;
HaTree *p = head;
do
{
while (p->lChild != NULL && p->rChild != NULL)
{
st[++sum] = p;
p = p->lChild;
}
if (sum >= 0)
{
p = st[sum];
sum--;
HaTrasTree (p);
p = p->lChild;
}
}
while (sum >= 0);
}
void HaTrasTree (HaTree *node)
{
HaTree *tmp = node->lChild;
node->lChild = node->rChild;
node->rChild = tmp;
}