GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python中的二叉树模块 · AugustLONG/algorithm@44fcf39

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • binary_tree_python.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎binary_tree_python.md‎

Copy file name to clipboardExpand all lines: binary_tree_python.md
+13-13Lines changed: 13 additions & 13 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -44,46 +44,46 @@ bintrees提供了丰富的API,涵盖了通常的多种应用。下面逐条说
4444
- 引用
4545

4646
如果按照一般模块的思路,输入下面的命令引入上述模块
47-
47+
4848
>>> import bintrees
49-
49+
5050
错了,这是错的,出现如下警告:(×××不可用,用×××)
5151

5252
Warning: FastBinaryTree not available, using Python version BinaryTree.
5353
Warning: FastAVLTree not available, using Python version AVLTree.
5454
Warning: FastRBTree not available, using Python version RBTree.
5555

5656
正确的引入方式是:
57-
57+
5858
>>> from bintrees import BinaryTree #只引入了BinartTree
5959
>>> from bintrees import * #三个模块都引入了
60-
60+
6161
- 实例化
62-
62+
6363
>>> btree = BinaryTree()
6464
>>> btree
6565
BinaryTree({})
6666
>>> type(btree)
6767
<class 'bintrees.bintree.BinaryTree'>
68-
68+
6969
- 逐个增加键值对:.__setitem__(k,v) .复杂度O(log(n))(后续说明中,都会有复杂度标示,为了简单,直接标明:O(log(n)).)
70-
70+
7171
>>> btree.__setitem__("Tom","headmaster")
7272
>>> btree
7373
BinaryTree({'Tom': 'headmaster'})
7474
>>> btree.__setitem__("blog","http://blog.csdn.net/qiwsir")
7575
>>> btree
7676
BinaryTree({'Tom': 'headmaster', 'blog': 'http://blog.csdn.net/qiwsir'})
77-
77+
7878
- 批量添加:.update(E) E是dict/iterable,将E批量更新入btree. O(E*log(n))
79-
79+
8080
>>> adict = [(2,"phone"),(5,"tea"),(9,"scree"),(7,"computer")]
8181
>>> btree.update(adict)
8282
>>> btree
8383
BinaryTree({2: 'phone', 5: 'tea', 7: 'computer', 9: 'scree', 'Tom': 'headmaster', 'blog': 'http://blog.csdn.net/qiwsir'})
84-
84+
8585
- 查找某个key是否存在:.__contains__(k) 如果含有键k,则返回True,否则返回False. O(log(n))
86-
86+
8787
>>> btree
8888
BinaryTree({2: 'phone', 5: 'tea', 7: 'computer', 9: 'scree', 'Tom': 'headmaster', 'blog': 'http://blog.csdn.net/qiwsir'})
8989
>>> btree.__contains__(5)
@@ -94,9 +94,9 @@ bintrees提供了丰富的API,涵盖了通常的多种应用。下面逐条说
9494
False
9595
>>> btree.__contains__(1)
9696
False
97-
97+
9898
- 根据key删除某个key-value:.__delitem__(key), O(log(n))
99-
99+
100100
>>> btree
101101
BinaryTree({2: 'phone', 5: 'tea', 7: 'computer', 9: 'scree', 'Tom': 'headmaster', 'blog': 'http://blog.csdn.net/qiwsir'})
102102
>>> btree.__delitem__(5) #删除key=5的key-value,即:5:'tea' 被删除.

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.