#!/usr/bin/python

class ABinTree(list):
	def parent(self,i):
		if i<len(self) and i>0 :
			return (i-1)/2
	
	def left(self,i):
		if 2*i+1<len(self):
			return 2*i+1

	def right(self,i):
		if 2*i+2<len(self):
			return 2*i+2

	def leftSibling(self,i):
		if i<len(self) and i>0 and not i%2:
			return i-1

	def rightSibling(self,i):
		if i+1<len(self) and i%2:
			return i+1
	
if __name__ == '__main__' :
	t=ABinTree(range(0,12))
	print 'tree =', t
	print 'parent(1)', t.parent(1)
	print 'left child(1)', t.left(1)
	print 'right child(1)', t.right(1)
	print 'left sibling(1)', t.leftSibling(1)
	print 'right sibling(1)', t.rightSibling(1)
