首页 > 代码库 > 二进制查找树转换为双向链表
二进制查找树转换为双向链表
完全按照海涛哥剑指offer里边的递归思路来写的,基本一样,仅作学习验证,努力锻炼,努力学习!
题目:输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表。要求不能创建任何新的结点,只调整指针的指向。
比如将二元查找树
10
/ \
6 14
/ \ / \
4 8 12 16
转换成双向链表
4=6=8=10=12=14=16。
code如下://Change a BSTree to a sorted double linklist struct BSTreeNode { int value; BSTreeNode *left; BSTreeNode *right; }head; //Create a node of BSTree for test BSTreeNode* CreateNode(int value) { BSTreeNode *node = new BSTreeNode(); node->value = http://www.mamicode.com/value;>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。