Searching in ABR

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

View file

@ -159,4 +159,18 @@ def planter(racine, val):
planter(racine.fd, val) planter(racine.fd, 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
``` ```