Best structure for (binary) trees?

Aahz aahz at pythoncraft.com
Sun Dec 7 11:05:44 EST 2003


In article <jVGAb.13860$UV7.5376 at news.get2net.dk>,
Rasmus <razor-report at daimi.au.dk> wrote:
>
>As partly novice in python I would like a piece of advise of how to
>implement (binary) trees the best way?

Assuming that nodes also contain data:

class Node:
    def __init__(self, data):
        self.data = data
        self.left = self.right = None

Assuming that you're a CS student looking for homework help, I'll leave
the rest of the implementation as an exercise.  You might also consider
looking at the bisect module.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.




More information about the Python-list mailing list