0

Python & binary tree help PLEASE?!?????????please please please help me in anyway :'(?

Write a Python program that :
a: Takes in as input a list of numbers (Note that you have to type in these numbers using the
keyboard)

using:

def insert(tree, key):
if len(tree) == 0:
return [key, [], []]
else:
if key < tree[0]:
return [tree[0], insert(tree[1], key), tree[2]]
else:
return [tree[0], tree[1], insert(tree[2], key)]

def construct(ls, tree):
if len(ls) == 0:
return tree
else:
return construct(ls[1:], insert(tree,ls[0]))

def main(ls):
if len(ls) == 0:
return []
else:
t = construct(ls, tree)
print t

ls = []

#Write code to enter your letters here one by one and add each one of them to the list ls

tree = []
main(ls)

c: Add a function called total() that takes in as input this list and and finds the sum of all the nodes in
the constructed binary tree.
d: Return as output, the total value of all the nodes in the binary tree.

i have no idea what to add by " #Write code to enter your letters here one by one and add each one of them to the list ls", please anyone help?? :( even steps or ANY help at all please:((((

3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by Lardmeister
0

You could indent code properly following Python rules and then you can just code taking one step at time and testing/printing the partial results for debugging.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.