Convert a given binary tree to double linked list

Posted lilyfindjob

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Convert a given binary tree to double linked list相关的知识,希望对你有一定的参考价值。

 public TreeNode binaryTree2List(TreeNode node)
	 {
		 if (node == null)
	            return node;
	  
	        // Convert to DLL using bintree2listUtil()
	        node = bintree2listUtil(node);
	        while (node.left!=null) {
				node=node.left;
				
			}
	        return node;
	 }
	 TreeNode bintree2listUtil(TreeNode node) 
	    {
	        if (node==null) {
				return node;
			}
	        if (node.left!=null) {
				TreeNode leftNode=bintree2listUtil(node.left);
				while (leftNode.right!=null) {
					leftNode=leftNode.right;
					
				}
				leftNode.right=node;
				node.left=leftNode;
			}
	        if (node.right!=null) {
				TreeNode rightNode=bintree2listUtil(node.right);
				while (rightNode.left!=null) {
					rightNode=rightNode.left;
					
				}
				rightNode.left=node;
				node.right=rightNode;
			}
	        return node;
	    }

  

 

以上是关于Convert a given binary tree to double linked list的主要内容,如果未能解决你的问题,请参考以下文章

[Algorithm] 1290. Convert Binary Number in a Linked List to Integer

LeetCode --- 1290. Convert Binary Number in a Linked List to Integer 解题报告

Convert Sorted Array to Binary Search Tree & Convert Sorted List to Binary Search Tree

Given two binary string, return their sum (also a binary string)

Convert Sorted Array to Binary Search Tree

CMake报错:add_subdirectory not given a binary directory but the given source directory