MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / interact_treap

Function interact_treap

data_structures/binary_tree/treap.py:121–155  ·  view source on GitHub ↗

Commands: + value to add value into treap - value to erase all nodes with value >>> root = interact_treap(None, "+1") >>> inorder(root) 1, >>> root = interact_treap(root, "+3 +5 +17 +19 +2 +16 +4 +0") >>> inorder(root) 0,1,2,3,4,5,16,17,1

(root: Node | None, args: str)

Source from the content-addressed store, hash-verified

119
120
121def interact_treap(root: Node | None, args: str) -> Node | None:
122 """
123 Commands:
124 + value to add value into treap
125 - value to erase all nodes with value
126
127 >>> root = interact_treap(None, "+1")
128 >>> inorder(root)
129 1,
130 >>> root = interact_treap(root, "+3 +5 +17 +19 +2 +16 +4 +0")
131 >>> inorder(root)
132 0,1,2,3,4,5,16,17,19,
133 >>> root = interact_treap(root, "+4 +4 +4")
134 >>> inorder(root)
135 0,1,2,3,4,4,4,4,5,16,17,19,
136 >>> root = interact_treap(root, "-0")
137 >>> inorder(root)
138 1,2,3,4,4,4,4,5,16,17,19,
139 >>> root = interact_treap(root, "-4")
140 >>> inorder(root)
141 1,2,3,5,16,17,19,
142 >>> root = interact_treap(root, "=0")
143 Unknown command
144 """
145 for arg in args.split():
146 if arg[0] == "+":
147 root = insert(root, int(arg[1:]))
148
149 elif arg[0] == "-":
150 root = erase(root, int(arg[1:]))
151
152 else:
153 print("Unknown command")
154
155 return root
156
157
158def main() -> None:

Callers 1

mainFunction · 0.85

Calls 3

eraseFunction · 0.85
splitMethod · 0.80
insertFunction · 0.70

Tested by

no test coverage detected