Recursive method

Anthony McDonald anthony at lokie.force9.net
Wed Jul 14 09:44:20 EDT 1999


Ralph Gauges <ralph.gauges at eml.villa-bosch.de> wrote in message
news:378C214F.3CF9CDD3 at eml.villa-bosch.de...
> Hans Nowak wrote:
> > You have a nested function here. (I say function, because it does not
> > look like a method... it's missing the self argument!
>
>
>
> Actualy it is a method, but JPython doesn't seem to have a
> self. I was missing that as well.
>
>
>
> >
> > So, to solve this, you could try a different approach... maybe
> >
> > (you said it's a method, right?)
> >
> > class Blahblah:
> >     ...
> >     def makeTree(self):
> >          ....
> >     def makenodes(self, C):
> >          ....
> >
>
>
>
> I tried that as well, but I got the same error message. Only
> after I moved the makenodes outside the class it worked.
> This might also be related to the missing 'self' in JPython
> since I can not call 'self.makenodes'.
> Since moving makenodes out of the class is actualy not what
> I want, I was wondering, if anybody has had a similar
> problem and found a solution.
>
>
>
> Thanks for the answers. Although it is still not, what I
> want it to be, it works and I can go on, till I (or someone
> else) find a better solution.
>
> Ralph

This should provide you with the basic framework to implement your tree.
class tree:
    def __init__(self, data):
        self.count=1
        self.item=data
        self.left=None
        self.right=None
    def add(self, data):
        if self.item == data:
            self.count=self.count+1
        elif data < self.item:
            if self.left == None:
                self.left = tree(data)
           else:
                self.left.add(data)
        elif data > self.item:
               if self.right == None:
                    self.right = tree(data)
               else:
                    self.right.add(data)
    def list(self, data):
        if self.left != None:
            self.left.list(data)
       data.append([self.item, self.count])
       if self.right != None:
           self.right.list(data)







More information about the Python-list mailing list