数据结构练习(10)求二元查找树的镜像
http://zhedahht.blog.163.com/blog/static/2541117420072159363370/
#include <stack> struct Node { int m_value; Node *m_left; Node *m_right; }; void getmirror(Node *root) { if (root == NULL) return ; Node *node = root->m_left; root->m_left = root->m_right; root->m_right = node; getmirror(root->m_left); getmirror(root->m_right); } void getmirror_2(Node *root) { if (root == NULL) return ; std::stack<Node*> stacknode; stacknode.push(root); while (stacknode.size()) { Node *node = stacknode.top(); stacknode.pop(); if (node->m_left) stacknode.push(node->m_left); if (node->m_right) stacknode.push(node->m_right); Node *temp = node->m_right; node->m_right = node->m_left; node->m_left = temp; } }
-------------------------------------------------------
kedebug
Department of Computer Science and Engineering,
Shanghai Jiao Tong University
E-mail: kedebug0@gmail.com
GitHub: http://github.com/kedebug
-------------------------------------------------------