@@ -128,14 +128,14 @@ cdef binary_tree_node *binary_tree_head_excise(binary_tree_node *self):
128
128
if self .left == NULL :
129
129
return self .right
130
130
if right:
131
- # move right branch to left, return left
131
+ # move right branch to left, return left
132
132
cur = self .left
133
133
while cur.right != NULL :
134
134
cur = cur.right
135
135
cur.right = self .right
136
136
cur = self .left
137
137
else :
138
- # move left branch to right, return right
138
+ # move left branch to right, return right
139
139
cur = self .right
140
140
while cur.left != NULL :
141
141
cur = cur.left
@@ -206,15 +206,15 @@ cdef class BinaryTree:
206
206
....: return [(k,v) for (k,v) in post.items() if v>10]
207
207
sage: test() # indirect doctest
208
208
[]
209
-
210
209
"""
211
210
binary_tree_dealloc(self .head)
212
211
213
- def insert (BinaryTree self , object key , object value = None ):
212
+ def insert (BinaryTree self , object key , object value = None ):
214
213
"""
215
214
Insert a key-value pair into the BinaryTree.
216
215
217
216
Duplicate keys are ignored.
217
+
218
218
The first parameter, key, should be an int, or coercible (one-to-one)
219
219
into an int.
220
220
@@ -298,13 +298,11 @@ cdef class BinaryTree:
298
298
"""
299
299
if self .head == NULL :
300
300
return None
301
- else :
302
- return binary_tree_get(self .head, key)
301
+ return binary_tree_get(self .head, key)
303
302
304
303
def contains (BinaryTree self , int key ):
305
304
"""
306
- Return ``True`` if a node with the given key exists
307
- in the tree, and ``False`` otherwise.
305
+ Return whether a node with the given key exists in the tree.
308
306
309
307
EXAMPLES::
310
308
@@ -318,11 +316,7 @@ cdef class BinaryTree:
318
316
"""
319
317
if self .head == NULL :
320
318
return False
321
- else :
322
- if binary_tree_get(self .head, key) is not None :
323
- return True
324
- else :
325
- return False
319
+ return binary_tree_get(self .head, key) is not None
326
320
327
321
def get_max (BinaryTree self ):
328
322
"""
@@ -432,7 +426,7 @@ cdef class BinaryTree:
432
426
433
427
def is_empty (BinaryTree self ):
434
428
"""
435
- Return ``True`` if the tree has no nodes.
429
+ Return whether the tree has no nodes.
436
430
437
431
EXAMPLES::
438
432
0 commit comments