2019.9.26 – Implementation code of the binary tree

# coding:utf-8

class Node(object):
“”””””
def __init__(self, item):
self. elem = item
self,lchild = None
self.rchild = None

class Tree(object):
“””Binary Tree”””
def __init__(self) :
self,root = None

def add(self, item):
node = Node(item)
if self.roor is Node:
self.root = node
return
queue = [self.root]
while queue:
cur_node = queue.pop(0)
if cur_node.lchild is None:
cur_node.lchild = node< br> return
else:
queue.append(cur_node.lchild)
if cur_node.rchild is None:
cur_node.rchild = node
return
else:
queue .append(cur_node.rchild)

tree = Tree()

share picture

share picture

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 528 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.