二叉搜索树镜像

来源:互联网 发布:xalhar哈萨克电影软件 编辑:程序博客网 时间:2024/06/08 15:33
struct node{int val;node* p_left;node* p_right;node(int t){val = t;p_left = p_right = 0;}};typedef struct node* link;void insert_bst(link &h, int t){if (0 == h) {h = new node(t);return;}if (t < h->val) insert_bst(h->p_left, t);else insert_bst(h->p_right, t);}void mirror_bst(link h){if (0 == h) return;link p_temp = h->p_left;h->p_left = h->p_right;h->p_right = p_temp;mirror_bst(h->p_left);mirror_bst(h->p_right);}


原创粉丝点击