Playing with recursions for my tree

Took me a bit to get these, but then it was just like, OH!!!!

I should have the whole python binary tree tested and ready to post soon!
Still not sure if this project is just a binary tree, or a binary search tree... need to do some more research to understand what all the differences are.
Terminology has been the stumbling block a lot of times for me.

Most exercises for this book require you to major amounts of discovering how things work, what they are, on your own.  I was stuck on how to look up what I wanted these recursions to do for me because I didn't know what to put in the search bar.

Someone in class says,  try accumulator,  and bam!

There's the material I needed to look at.

So the hardest part about trying to learn something you know very little about?
Not knowing what the words mean, or not knowing what word fits the thing you need to find.  (hint: ask someone for a word, or, just google the words until you find the fit)

Kinda like you find a wikipedia page about something and it's full of terminology highlighted in blue, and they're unfamiliar, and then it's like.... crap, this is going to take a while.

https://en.wikipedia.org/wiki/Quantum_entanglement
https://en.wikipedia.org/wiki/Pythagorean_theorem
https://en.wikipedia.org/wiki/Iambic_pentameter
https://en.wikipedia.org/wiki/Binary_search_tree

A couple of my recursions that I used:



def dump(self):
       
        west = self.root_node.right
        east = self.root_node.left
        if east:
            print(f"East branch: {east}")
            self.recursDump(east)
            print("********** END EAST************")
           
        if west:
            print(f"West branch: {west}")
            self.recursDump(west)
            print("********** END WEST************")
           
       
           
    def recursDump(self, branch):
       
        if branch == None:
            print(" ")
        else:
            left_child = branch.left
            right_child = branch.right
            if left_child:
                print(left_child)
            if right_child:
                print(right_child)
            self.recursDump(right_child)
            self.recursDump(left_child)
            return branch
           
    def count(self):
        trunk = self.root_node
        keyslist = []
        result = self.recurs_helper(trunk, keyslist)
        print(result)
        count = len(result)
        return count
       
    def make_key_list(self):
        # same as count different return
        trunk = self.root_node
        keyslist = []
        result = self.recurs_helper(trunk, keyslist)
        #print(result)
        return result
       
    def recurs_helper(self, branch, alist):
        if branch == None:
            pass
        else:
            left_sprout = branch.left
            right_sprout = branch.right
            if left_sprout:
                self.list_add(left_sprout, alist)
            if right_sprout:
                self.list_add(right_sprout, alist)
            self.recurs_helper(left_sprout, alist)
            self.recurs_helper(right_sprout, alist)
            return alist
               
           
    def list_add(self, something, alist):       
        if something:
            alist.append(something.key)

Comments

Popular posts from this blog

playing with color in powershell python

JavaScript Ascii animation with while loops and console.log

playing with trigonometry sin in pygame