''' Homework 4
-- Due Sunday, Sept 27th at 11:59pm
-- Always write the final code yourself
-- Never use a library function that solves the problem
-- If you collaborated with a peer, mention them
-- Cite any websites you referenced
-- Use the PEP-8 checker for full style points:
https://pypi.python.org/pypi/pep8
'''
class Rational(object):
''' Implement a rational numbers class. Include the following
magic methods: init, str, repr, add, sub, mul, truediv, and
lt, gt, ge, le, ne, eq.
Also include a from_string class method, that creates a Rational
from a string of the form "a/b".
Some notes:
-- Numeric operations should return a new Rational Object
-- All numbers should be in lowest terms at all times.
-- Denominators should never be negative (e.g. 2/-3 should be
written as (-2/3))
-- If the denominator is 1, only print the numerator.
-- use functools.total_ordering to supply the comparison methods
https://docs.python.org/3.4/library/functools.html
'''
pass
def depth(old_f):
''' Write a decorator that overrides the standard behavior of
a function that returns True or False and instead returns
0 for False or n for number of recursive calls needed to
return True.
'''
pass
class Node(object):
''' Implement a node class for a binary search tree.
See here: http://en.wikipedia.org/wiki/Binary_search_tree
The examples in the test file illustrate the desired behavior.
Each method you need to implement has its own docstring
with further instruction.
Keep a count (called "count") of the total number of nodes created.
'''
def __init__(self, val, left=None, right=None):
pass
def __repr__(self):
'''If the node has neither a left nor right child,
simply return Node(val). Else, return Node(x, val, y),
where x and y are recursive calls that return the
left and right children, respectively.
'''
pass
def search(self, element):
''' Finds whether a given element is in the tree.
Returns True if the element is found, else returns False.
Give it the depth decorator you defined earlier.
'''
def insert(self, element):
''' Insert an element into a binary search tree rooted
at this Node. After insertion, return the modified node.
Our implementation will allow duplicate nodes. The left subtree
should contain all elements <= to the current element, and the
right subtree will contain all elements > the current element.
'''
pass
def elements(self):
''' Return a list of the elements visited in an inorder traversal:
http://en.wikipedia.org/wiki/Tree_traversal
Note that this should be the sorted order if you've inserted all
elements using your previously defined insert function.
'''
pass
def main():
pass
if __name__ == "__main__":
main()