Created
August 12, 2015 01:20
-
-
Save JAChapmanII/9f5ca0c8a6c5a1c05fe8 to your computer and use it in GitHub Desktop.
python bsp skeleton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point: | |
def __init__(self, i, x, y): | |
self.i = i | |
self.x = x | |
self.y = y | |
def __repr__(self): | |
if self.i == -1: | |
return "[(%s, %s)]" % (self.x, self.y) | |
else: | |
return "[%s @ (%s, %s)]" % (self.i, self.x, self.y) | |
class Node: | |
def __init__(self, p, l, r): | |
self.p = p | |
self.left = l | |
self.right = r | |
def __repr__(self): | |
return "<implement me too>" | |
null = None | |
def Just(p): | |
return Node(p, null, null) | |
p1 = Point(1,9,9) | |
p2 = Point(2,6,8) | |
p3 = Point(3,3,8) | |
p4 = Point(4,4,6) | |
p5 = Point(5,7,7) | |
p6 = Point(6,7,3) | |
p7 = Point(7,9,2) | |
p8 = Point(8,5,1) | |
p9 = Point(9,3,4) | |
p10 = Point(10,1,4) | |
p11 = Point(11,3,1) | |
points = [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11] | |
root = \ | |
Node(p8, | |
Node(p10, | |
Node(p9, | |
Just(p11), | |
null), | |
Node(p3, | |
null, | |
Just(p4))), | |
Node(p5, | |
Node(p6, | |
null, | |
Just(7)), | |
Node(p1, | |
Just(p2), | |
null))) | |
def find(Z, root): | |
raise "implement me!" | |
Z = Point(-1, 1, 5) | |
print("finding %s" % (Z)) | |
print("in:\n%s" % (root)) | |
f = find(Z, root) | |
if f is None: | |
print("%s not in tree!" % (Z)) | |
else: | |
print("%s is %s!" % (Z, f.i)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment