binary search trees using classes

christy johnson christy_girl99 at yahoo.com
Sun Oct 28 01:13:57 EDT 2001


Hi,
I was wondering if anyone had a binary search tree
module I could use? I need to write a program that
counts the number of occurrences of each word in a
file, and outputs the word and corresponding counts 
alphabetically. For example, if input is

Have a nice day. Have a nice day. 
Have a nice day.
Have a nice day.

the output is

a 4
day 4
have 4
nice 4

The code has to be modular based on classes. I'm
thinking of making a
tree node that looks like this  

bintree[ [key, data], left, right] ,  

where I can traverse the tree by simply incrementing
the current root 
to the appropriate child.

temp = bintree.root
temp = temp[1]        #move to the left child.
temp = temp[2]        #move to the right child.

but I don't know how to implement it correctly using
classes. (i.e 
using def __init__(self), etc)

I'm new to this python language so I would appreciate
anyone's help.

Thanks in advance :)
Christy



__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com




More information about the Python-list mailing list