Searching in ABR

This commit is contained in:
Gabriel Augendre 2015-04-27 08:46:03 +02:00
parent 6b6dd822f1
commit 11e383bcc6

View file

@ -160,3 +160,17 @@ def planter(racine, val):
else: else:
racine.fd = new Noeud(val=val, fg=None, fd=None) 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
```