本文介绍了如何设计通用二叉树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



据我所知,有两种二元树

1。二进制搜索树(BST)和

2.通用二叉树



我正在寻找在python中实现通用二叉树。我主要是在通用二叉树中设计和实现插入操作。



例如:

Hi everyone,

As I understand there are two kinds of binary trees:
1. Binary search trees (BST) and
2. Generic Binary trees

I am looking for implementing a generic binary tree in python. I am mainly looking at designing and implementing the insertion operation in the generic binary tree.

For Example :

# input is a list
L = [1,2,3,4,5,6,7,8,9]

# I expect the output to be a tree

'''
            1   
           / \
          /   \
         2     3
        / \   / \
       /   |  |  \
      4    5  6   7
     / \
    /   \
   8     9

'''
# I don`t want it to be printed in this manner, but I expect some data structure which stores the generic binary tree in this fashion. 





提前致谢!



Thanks in advance !

推荐答案

这篇关于如何设计通用二叉树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 14:42