def __rearrangeLinks(self, a):
        """ Rearrange links when adding a new node """
        if self.valcnt != 0:            
            if a < self.values[0] and not self.isLeafNode() and self.refcnt < 3: 
                # shift all the links to the right when adding new in element
                self.__insertLink(0, None)
            elif self.valcnt == 2 and self.refcnt == 3 and self.values[self.valcnt - 1] > a > self.values[0]:
                # rearrange middle links when adding med element
                self.__insertLink(1, None)
 Rearrange links when adding a new node 
recipes/Python/577898_23_Tree/recipe-577898.py