Searching in ABR
This commit is contained in:
parent
6b6dd822f1
commit
11e383bcc6
1 changed files with 14 additions and 0 deletions
|
@ -159,4 +159,18 @@ def planter(racine, val):
|
|||
planter(racine.fd, val)
|
||||
else:
|
||||
racine.fd = new Noeud(val=val, fg=None, fd=None)
|
||||
```
|
||||
|
||||
### Rechercher dans un ABR
|
||||
```python
|
||||
def recherche(racine, val):
|
||||
cur_node = racine
|
||||
while cur_node:
|
||||
if cur_node.val == val:
|
||||
return True
|
||||
else if cur_node.val > val:
|
||||
cur_node = cur_node.fg
|
||||
else:
|
||||
cur_node = cur_node.fd
|
||||
return False
|
||||
```
|
Loading…
Reference in a new issue