To prove safety offer_ binary tree _ binary search trees and doubly-linked list

Binary search trees and doubly-linked list

Description Title
input a binary search tree, the conversion into a binary search tree sort of doubly linked list. Requirements can not create any new node, point to only adjust the tree node pointer.

This question is too difficult, I will not do T_T, the introduction of direct reference to the answer it.

# -*- coding:utf-8 -*-
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
class Solution:
    def __init__(self):
        self.listHead = None
        self.listTail = None
    def Convert(self, pRootOfTree):
        if pRootOfTree==None:
            return
        self.Convert(pRootOfTree.left)
        if self.listHead==None:
            self.listHead = pRootOfTree
            self.listTail = pRootOfTree
        else:
            self.listTail.right = pRootOfTree
            pRootOfTree.left = self.listTail
            self.listTail = pRootOfTree
        self.Convert(pRootOfTree.right)
        return self.listHead
Published 31 original articles · won praise 0 · Views 711

Guess you like

Origin blog.csdn.net/freedomUSTB/article/details/105181288