From 11e383bcc6bc20c4bea8c55a22f470bac99c0ff3 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 27 Apr 2015 08:46:03 +0200 Subject: [PATCH] Searching in ABR --- algo_avancee/arbres.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/algo_avancee/arbres.md b/algo_avancee/arbres.md index 8b0d114..01270d0 100644 --- a/algo_avancee/arbres.md +++ b/algo_avancee/arbres.md @@ -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 ``` \ No newline at end of file