Chinaunix首页 | 论坛 | 博客
  • 博客访问: 347758
  • 博文数量: 135
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1106
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-20 09:56
文章分类

全部博文(135)

文章存档

2017年(3)

2016年(18)

2015年(69)

2014年(39)

2013年(6)

我的朋友

分类: C/C++

2015-10-27 12:31:36

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);
    }
}



阅读(381) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~