0

Hi all,

I'm required to implement a method for a "**TernarySearchTree**" object/class.

Basically, a Ternary search tree is just like a binary tree except it has three children instead of two.

Ternary Search Tree could only manipulate it's root.

Now the method should create and return an alphabetically sorted list consisting of exactly the strings represented in the ternary search tree. for example it should return something like:

You could check this link to view the shape of the tree:

http://www.ddj.com/showArticle.jhtml?documentID=ddj9804a&pgno=4

Now my code gives this result: (for some reason)...

My code:

```
def collect_sorted (self, word = '', list_words = []):
if self.root.centre.splitchar == '$':
word+=self.root.splitchar
list_words.append(word)
return
if self.root.left:
pointer = self.root
self.root = self.root.left
self.collect_sorted(word)
self.root = pointer
if self.root.centre.splitchar != '$':
pointer = self.root
word += self.root.splitchar
self.root = self.root.centre
self.collect_sorted(word)
if self.root.right:
pointer = self.root
self.root = self.root.right
self.collect_sorted(word)
self.root = pointer
return list_words
```

I would really appreciate it if someone could help me figure out what's wrong..

Thanks a lot,

Blackrobe =)