struct BTree
{
int data;
struct BTree *left;
struct BTree *right;
};
void *change(BTree *root)
{
if (root == NULL)
return;
BTree *temp = root->left;
root->left = root->right;
root->right = temp;
change(root->left);
change(root->right);
}
//非递归实现
void *change(BTree * change)
{
if (change == NULL)
return;
Queue qu;
qu.push(change);
BTree *ptree;
while (!qu.empty())
{
ptree = qu.front();
qu.pop();
BTree *temp = ptree->left;
ptree->left = ptree->right;
ptree->right = temp;
if (ptree->left != NULL)
qu.push(ptree->left);
if (ptree->right != NULL)
qu.push(ptree->right);
}
}
阅读(414) | 评论(0) | 转发(0) |