コード例 #1
0
def findMax(gL: IntList) -> int:
    """
    finds the maximum value of an IntList
    """
    if gL is None or gL.nil:
        return None
    current_max = gL.first(
    )  #assign the current max to the first one to avoid one comparison
    gL = gL.rest()  # reassign gL to be the rest of the list
    while gL.nil is False:
        if gL.first() > current_max:
            current_max = gL.first()
        gL = gL.rest()
    return current_max
コード例 #2
0
def insert(i:int, k:int, aL:IntList) -> IntList :
    if aL.first() == k:
        return aL.cons(i)
    return insert(i, k, aL.rest()).cons(aL.first())