back to LMPTHW
Started working on the next exercise for class again,
((signed back up after realizing how regardless of issues stopping me from
going at the speed I was, I should continue))
Ternary search trees. In the process of memorizing some code for it, I always have to understand what it is I'm comiting to memory, or It will almost never stick in my head.
Not sure WHAT I'm doing wrong... but if I figure it out I'll update.
It's not working at all like I thought.... So here's a pic of what I'm getting,
and the code for my print will be below it. *I think I'm setting the key,value wrong*
update: OHHHH.... ok figured it out. the high lo isn't set until you add more strings...... and then we have a high low.... Updating print method at bottom.
So... why set the root as all the eq's? hrmmm....
The actual TSTree code is part of class, so I'm not going to put it in until I can get my own wacky version written to see if I can explain it.
Print method:
```
class PrintTSTree(object):
def graphical(self, branch):
if branch != None:
print("branch.key = ", branch.key)
print("branch.eq = ", branch.eq)
print("branch.low = ", branch.low)
print("branch.high = ", branch.high)
print("branch.value = ", branch.value)
if branch.eq != None:
self.graphical(branch.eq)
if branch.high != None:
print(" \n >>>>>>>>>>>>>>>>> greater >>>> \n")
print("branch high = ")
self.graphical(branch.high)
if branch.low != None:
print("\n <<<<<<<<<<<<<<<<< lower <<<<<< \n")
print("branch low = ")
self.graphical(branch.low)
else:
print("<<<< branch end >>>>")
```
How I'm implementing it:
spam = TSTree()
printtree = PrintTSTree()
spam.set('jackalope', 'root')
printtree.graphical(spam.root)
((signed back up after realizing how regardless of issues stopping me from
going at the speed I was, I should continue))
Ternary search trees. In the process of memorizing some code for it, I always have to understand what it is I'm comiting to memory, or It will almost never stick in my head.
Not sure WHAT I'm doing wrong... but if I figure it out I'll update.
It's not working at all like I thought.... So here's a pic of what I'm getting,
and the code for my print will be below it. *I think I'm setting the key,value wrong*
update: OHHHH.... ok figured it out. the high lo isn't set until you add more strings...... and then we have a high low.... Updating print method at bottom.
So... why set the root as all the eq's? hrmmm....
The actual TSTree code is part of class, so I'm not going to put it in until I can get my own wacky version written to see if I can explain it.
Print method:
```
class PrintTSTree(object):
def graphical(self, branch):
if branch != None:
print("branch.key = ", branch.key)
print("branch.eq = ", branch.eq)
print("branch.low = ", branch.low)
print("branch.high = ", branch.high)
print("branch.value = ", branch.value)
if branch.eq != None:
self.graphical(branch.eq)
if branch.high != None:
print(" \n >>>>>>>>>>>>>>>>> greater >>>> \n")
print("branch high = ")
self.graphical(branch.high)
if branch.low != None:
print("\n <<<<<<<<<<<<<<<<< lower <<<<<< \n")
print("branch low = ")
self.graphical(branch.low)
else:
print("<<<< branch end >>>>")
```
How I'm implementing it:
spam = TSTree()
printtree = PrintTSTree()
spam.set('jackalope', 'root')
printtree.graphical(spam.root)
Comments
Post a Comment