def merge(list_a, length_a, list_b, length_b):
    """
    Merges two lists together by always choosing the smaller of the two values
    from the front of the lists. When one list is exhausted, the other list has
    simply all its elements added to the end of the merged list.
    """
    index_a, index_b = 0, 0
    merged_list = []

    while index_a < length_a and index_b < length_b:
        if list_a[index_a] < list_b[index_b]:  # Add the smallest of the two
            merged_list.append(list_a[index_a])
            index_a += 1
        else:
            merged_list.append(list_b[index_b])
            index_b += 1

    if index_a < length_a:  # The list who hasn't reached its end is not exhausted
        merged_list.extend(list_a[index_a:])
    else:
        merged_list.extend(list_b[index_b:])

    return merged_list