Given a Binary Tree (Bt), convert it to a Doubly Linked List(DLL). The left and right pointers in nodes are to be used as previous and next pointers respectively in converted DLL. The order of nodes in DLL must be same as Inorder of the given Binary Tree. The first node of Inorder traversal (left most node in BT) must be head node of the DLL.
private TreeNode prev; private TreeNode head; public TreeNode bstToDLL(TreeNode node) { if(node == null) return null; bstToDLL(node.left); node.left = prev; if(prev != null) { prev.right = node; } else { head = node; } prev = node; bstToDLL(node.right); return head; }
Reference:
http://www.algorithmsandme.com/2013/10/binary-search-tree-to-doubly-linked.html
相关推荐
Creating linked list, doubly linked list and Binary Tree in VB.Net 2005. sourcecode in Spanish
BinaryTree-BinaryTree
This is a binary tree search implementation.
binary tree 的C语言实现算法,需要在linux环境下编译
BinaryTree-源码.rar
Construct Binary Tree from Preorder and Inorder Traversal 根据先序,中序建立二叉树
懂的人自然懂:) 用C#写的binarytree
2.binaryTree树 标准的二叉树。 实现了各种算法,增删查改等等
心希盼 C++ STL 二叉树 详细请看“心希盼 binaryTree.doc”
二叉树的实现,各种方法,构造函数,析构函数,前序遍历,中序遍历,后续遍历,层次序遍历
BinaryTreeSort的java实现,简单的二叉树排序
constructing a binary tree
BinaryTree: 用于学习二叉树的Python库
For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack operations are: push(1); push(2); push(3); pop(); pop(); push(4); pop(); pop(); push(5...
C++实现 操作函数包括先序、中序、后序遍历,求深度,深度、广度遍历 构建二叉树
数据结构教学课件:chapter5 A Binary Tree Node ADT.ppt
有序二叉树创建 有序二叉树查找 二叉树遍历 有序二叉树删除 类模版实现的有序二叉树
二叉树的实现代码,我的博客“Java——二叉树的基础实现”的代码。 https://blog.csdn.net/J_fla/article/details/103236673
二叉树前序遍历,leetcode
Flatten-Binary-Tree-To-Linked-List