コード例 #1
0
def insert_animate(block_pos, shelf, high):
    b = shelf.pop(block_pos)
    for i in range(high):
        if shelf[i].size > b.size:
            shelf.insert(i, b)
            return shelf

    shelf.insert(high, b)
    return shelf
コード例 #2
0
def insert_animate_1(block_pos, shelf, high):
    block = shelf.pop(block_pos)
    position = 0
    for i in shelf[:high]:
        if i.size < block.size:
            position += 1
    shelf.insert(position, block)
    # optional to return shelf but we do this for debugging
    return shelf
コード例 #3
0
def insert_animate(block_pos, shelf, high):
    b_size = shelf[block_pos].size
    orig_size = len(shelf)
    b = shelf.pop(block_pos)
    for i in range(0, high):
        if b_size <= shelf[i].size:
            shelf.insert(i, b)
            break
    if len(shelf)<orig_size:
        shelf.insert(high, b)
    return shelf
コード例 #4
0
def insert_animate(block_pos, shelf, high):

    b = shelf.pop(block_pos)

    for index in range(0, high):
        if shelf[index].size >= b.size:
            shelf.insert(index, b)
            return shelf

    shelf.insert(high, b)
    return shelf
コード例 #5
0
ファイル: mission09-template.py プロジェクト: mclsun/CS1010X
def insert_animate(block_pos, shelf, high):
    """
    Pops the block at block_pos and inserts it in the position in the shelf
    such that its size is less than or equal to the one succeeding it. It searches
    for this position within zero and high.

    NOTE: To actually see the animation, please uncomment the testing function
    below.
    """
    block = shelf.pop(block_pos)
    new_pos = high
    for i in range(0, high):
        if block.size < shelf[i].size:
            new_pos = i
            break
    shelf.insert(new_pos, block)
    # optional to return shelf but we do this for debugging
    return shelf
コード例 #6
0
def insert_animate(block_pos, shelf, high):
    """
    Pops the block at block_pos and inserts it in the position in the shelf
    such that its size is less than or equal to the one succeeding it. It searches
    for this position within zero and high.

    NOTE: To actually see the animation, please uncomment the testing function
    below.
    """
    low = 0
    while low < high: # insert_animate(3, s, 3) # 4
        block = shelf.pop(block_pos) # (1, 2, 6, __ 8, 3, 9)
        if block.size > shelf[low].size:
            low += 1
            shelf.insert(low, block)
            block_pos = low
        elif block.size <= shelf[low].size:
            shelf.insert(low, block)
            break
            
    # optional to return shelf but we do this for debugging
    return shelf