@@ -0,0 +1,1407 @@
+class Tree:%0A    class Position:%0A        def element(self):%0A            raise NotImplementedError('must be implemented by subclass')%0A%0A        def __eq__(self, e):%0A            raise NotImplementedError('must be implemented by subclass')%0A%0A        def __ne__(self, e):%0A            raise NotImplementedError('must be implemented by subclass')%0A%0A    def root(self):%0A        raise NotImplementedError('must be implemented by subclass')%0A%0A    def parent(self, p):%0A        raise NotImplementedError('must be implemented by subclass')%0A%0A    def num_children(self, p):%0A        raise NotImplementedError('must be implemented by subclass')%0A%0A    def children(self, p):%0A        raise NotImplementedError('must be implemented by subclass')%0A%0A    def __len__(self):%0A        raise NotImplementedError('must be implemented by subclass')%0A%0A    def is_root(self, p):%0A        return self.root() == p%0A%0A    def is_leaf(self, p):%0A        return self.num_children(p) == 0%0A%0A    def is_empty(self):%0A        return len(self) == 0%0A%0A    def depth(self, p):%0A        if self.root() == p:%0A            return 0%0A        else:%0A            return 1 + self.depth(self.parent(p))%0A    %0A    def _height(self, p):%0A        if self.is_leaf(p):%0A            return 0%0A        else:%0A            return 1 + max(self._height(c) for c in self.children(p))%0A%0A    def height(self, p=None):%0A        if p == None:%0A            return self._height(self.root())%0A        %0A%0A

Add AbstractTree base class