def exchange(heap, posa, posb): """ Intercambia los elementos en las posiciones posa y posb del heap """ try: lt.exchange(heap['elements'], posa, posb) except Exception as exp: error.reraise(exp, 'heap:exchange')
def exchange(lst, pos1, pos2): """ Intercambia la informacion en las posiciones pos1 y pos2 de la lista. Args: lst: La lista a examinar pos1: Posición del primer elemento pos2: Posiocion del segundo elemento Raises: Exception """ try: lt.exchange(lst, pos1, pos2) except Exception as exp: error.reraise(exp, 'List->exchange: ')
def funcionsink(lst, i, size, cmpfunction): """ Implementacion de un sink sobre listas. """ rs=i*2 ls=i*2+1 follower=i stop=False while (rs in range(1, size)) and (ls in range(1,size)) and not stop: root=lt.getElement(lst,follower) Right_son=lt.getElement(lst, rs) Left_son=lt.getElement(lst, ls) if cmpfunction(root, Right_son): lt.exchange(lst, follower, rs) if cmpfunction(Right_son, Left_son): lt.exchange(lst, follower, ls) follower=rs elif cmpfunction(root, Left_son): lt.exchange(lst, follower, ls) follower=ls else: stop=True rs=follower*2 ls=follower*2+1