def select(map, k):
    """
    Retorna la siguiente llave a la k-esima llave mas pequeña de la tabla
    Args:
        map: La tabla de simbolos
        pos: la pos-esima llave mas pequeña
    Returns:
        La llave más pequeña mayor o igual a Key
    Raises:
        Exception
    """
    if (map['type'] == 'BST'):
        return bst.select(map, k)
    else:
        return rbt.select(map, k)
Beispiel #2
0
def test_select(tree):
    tree = bst.put(tree, 23, 'book21')
    tree = bst.put(tree, 7, 'book7')
    tree = bst.put(tree, 30, 'book30')
    tree = bst.put(tree, 5, 'book5')
    tree = bst.put(tree, 4, 'book4')
    tree = bst.put(tree, 3, 'book3')
    tree = bst.put(tree, 20, 'book20')
    tree = bst.put(tree, 25, 'book25')
    tree = bst.put(tree, 35, 'book35')
    tree = bst.put(tree, 29, 'book29')
    tree = bst.put(tree, 11, 'book11')
    tree = bst.put(tree, 15, 'book15')
    tree = bst.put(tree, 10, 'book10')
    assert bst.size(tree) == 13
    assert bst.select(tree, 6) == 15