Example #1
0
def change_smallest_value(number_stack):
    
    
    length1 = number_stack.get_max_size()
    copy_stack = Stack(length1)
    extra_stack = Stack(length1)
    extra_stack2 = Stack(length1)
    
    temp = number_stack.pop()
    min_stack = temp
    copy_stack.push(min_stack)
    
    while not number_stack.is_empty() :
        temp_min = number_stack.pop()
        if temp_min < min_stack :
            min_stack = temp_min
            copy_stack.push(temp_min)
        else :
            copy_stack.push(temp_min)

    while not copy_stack.is_empty() :
        temp_min = copy_stack.pop()
        
        if temp_min ==  min_stack :
            extra_stack.push(temp_min)
        elif temp_min !=  min_stack :
            extra_stack2.push(temp_min)
    
    while not extra_stack2.is_empty() :
        temp_min = extra_stack2.pop()
        copy_stack.push(temp_min)
       
    while not copy_stack.is_empty() :
        temp_min = copy_stack.pop() 
        extra_stack.push(temp_min) 
        
    return extra_stack   
Example #2
0
def separate_boxes(box_stack):
    length = box_stack.get_max_size()
    temp_stack = Stack(length)
    que = Queue(length)
    while not box_stack.is_empty():
        temp_box = box_stack.pop()

        if temp_box == "Red" or temp_box == "Green" or temp_box == "Blue":
            temp_stack.push(temp_box)
        else:
            que.enqueue(temp_box)

    while not temp_stack.is_empty():
        temp_box = temp_stack.pop()
        box_stack.push(temp_box)

    return que