{"id":1067,"date":"2023-03-24T09:47:07","date_gmt":"2023-03-24T01:47:07","guid":{"rendered":""},"modified":"2023-03-24T09:47:07","modified_gmt":"2023-03-24T01:47:07","slug":"Python \u4e8c\u53c9\u6811","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1067.html","title":{"rendered":"Python \u4e8c\u53c9\u6811"},"content":{"rendered":"
\n
Python \u4e8c\u53c9\u6811\u8be6\u7ec6\u64cd\u4f5c\u6559\u7a0b<\/span>\n <\/div>\n \u4e00\u4e2a\u8282\u70b9\u88ab\u6807\u8bb0\u4e3a\u6839\u8282\u70b9\u3002<\/span> <\/body>
\n \u9664\u6839\u8282\u70b9\u5916\u7684\u6bcf\u4e2a\u8282\u70b9\u90fd\u4e0e\u4e00\u4e2a\u7236\u8282\u70b9\u5173\u8054\u3002<\/span>
\n \u6bcf\u4e2a\u8282\u70b9\u53ef\u4ee5\u5177\u6709chib\u8282\u70b9\u7684\u7f16\u53f7\u3002<\/span> <\/p>\n\u521b\u5efa\u6839<\/h3>\n
# Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-15<\/span>
class <\/span>Node:
def <\/span>__init__(self, data):
self.left = None
self.right = None
self.data = data
def <\/span>PrintTree(self):
print(self.data)
root = Node(10)
root.PrintTree<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n 10
<\/span><\/code><\/pre>\n<\/p><\/div>\n\u63d2\u5165\u6811\u4e2d<\/h3>\n
# Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-15<\/span>
class <\/span>Node:
def <\/span>__init__(self, data):
self.left = None
self.right = None
self.data = data
def <\/span>insert(self, data):
# Compare the new value with <\/span>the parent node
<\/span> if <\/span>self.data:
if <\/span>data < self.data:
if <\/span>self.left is <\/span>None:
self.left = Node<\/span>(data)
else:<\/span>
self.left.insert<\/span>(data)
elif <\/span><\/span>data > self.data:
if <\/span>self.right is <\/span>None:
self.right = Node<\/span>(data)
else:<\/span>
self.right.insert<\/span>(data)
else:<\/span>
self.data = data
# print <\/span>the tree
<\/span> def <\/span>PrintTree(self):
if <\/span>self.left:
self.left.PrintTree<\/span>()
print( self.data),
if <\/span>self.right:
self.right.PrintTree<\/span>()
# Use the insert method to add nodes
<\/span> root = Node(12)
root.insert<\/span>(6)
root.insert<\/span>(14)
root.insert<\/span>(3)
root.PrintTree<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n3 6 12 14
<\/span><\/code><\/pre>\n<\/p><\/div>\n\u904d\u5386\u4e00\u68f5\u6811<\/h2>\n
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Python \u4e8c\u53c9\u6811zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[126],"tags":[],"class_list":["post-1067","post","type-post","status-publish","format-standard","hentry","category-python3"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1067"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1067"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1067\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}