Hi I am trying to write a red-black tree implementation in
python. I am very new to python and appologize if my question is terribly
stubid. But I ran into some trouble. I have a class and in it there
are functions but when I try to run the code I have I just get an error on one
of the functions “global name ‘balancedFourNode’ is not
defined” Now of course I realize that I am doing something wrong
when defining the function but I just can’t seem to find it. Any insight would be greatly appreciated. Another thing, I’ll just put in a code snip but I am
not sure if it is enough for you guys to see the problem, how ever the class is
almost 200 lines so I just didn’t want to put it all in the post. Many thanks, Anna M. class node: def __init__(self,g=None): self.data=""> self.parent=None
self.child=[None,None] # color 0 =
black, 1 = red self.color = 0 # NB. changed
june 7th # Kids were two
and named right and left, respectively # Now a node can
have many children # used in 2-3-4
trees and other fun trees. def left(self,x): self.child[0]=x x.parent=self return self def right(self,x): self.child[1]=x x.f=self return self def b(self,l): self.child=l[:] for child in l:
child.f=self return self def noOfKids(self): kids = 0 if self.child[0]
!= None:
kids += 1 if self.child[1]
!= None:
kids += 1 return kids def balancedFourNode(self): children = 0 children =
noOfKids(self) if children == 2: if
child[0].color == 1:
red += 1
if child[1].color == 1:
red += 1 if red == 2:
return 1 else:
return 0 |
-- http://mail.python.org/mailman/listinfo/python-list