如何在Python中的Tree`s节点中添加列表?

时间:2017-11-07 17:22:22

标签: python list avl-tree

我正在尝试在我的AVL树的这个节点内创建一个列表,我也试过一个函数,有人有一些库要导入或有些想法吗?

#import random, math
import re
outputdebug = False 

def debug(msg):
    if outputdebug:
    print msg

class Node():
    def __init__(self, key):
        self.key = key
        self.left = None 
        self.right = None 
        self.list = [] #list at the node

class AVLTree():
    def __init__(self, *args):
        self.node = None 
        self.height = -1  
        self.balance = 0; 

    def ad_list(self, value):
        self.list.append(value) #function trying to add

    def print_list(self):
        print self.list

1 个答案:

答案 0 :(得分:0)

您的AVLTree班级没有列表,只有Node班级:

self.node.list.append(value) #function trying to add