Exemplo n.º 1
0
#     print(list1)
#     list2=[]
#     for i in range(0,len(list1)):
#         if list1[i]=="Red" or list1[i]=="Green" or list1[i]=="Blue":
#             list2.append(list1.pop(i))
#
#     print(list2)
#     print(list1)
#     box_stack.push()
#Remove pass and write your logic here

#Use different values for stack and test your program
box_stack = Stack(8)
box_stack.push("Red")
box_stack.push("Magenta")
box_stack.push("Yellow")
box_stack.push("Red")
box_stack.push("Orange")
box_stack.push("Green")
box_stack.push("White")
box_stack.push("Purple")
print("Boxes in the stack:")
box_stack.display()
result = separate_boxes(box_stack)
print()
print("Boxes in the stack after modification:")
box_stack.display()
print("Boxes in the queue:")
result.display()
Exemplo n.º 2
0
        list1.append(stack1.pop())
    while (not (stack2.is_empty())):
        list1.append(stack2.pop())
    list1.sort()
    for i in list1:
        output_stack.push(i)

    return output_stack


#Pass different values to the function and test your program
stack2 = Stack(3)
stack2.push(9)
stack2.push(11)
stack2.push(15)

stack1 = Stack(4)
stack1.push(3)
stack1.push(7)
stack1.push(10)
stack1.push(21)

print("The elements in stack1 are:")
stack1.display()
print("The elements in stack2 are:")
stack2.display()
print()
output_stack = merge_stack(stack1, stack2)
print("The elements in the output stack are:")
output_stack.display()
Exemplo n.º 3
0
    for i in m:
        number_stack.push(i)
    #write your logic here

    return number_stack


#Add different values to the stack and test your program
number_stack = Stack(8)
number_stack.push(7)
number_stack.push(8)
number_stack.push(5)
number_stack.push(66)
number_stack.push(5)
print("Initial Stack:")
number_stack.display()
change_smallest_value(number_stack)
print("After the change:")
number_stack.display()

# from src.DS_stack import Stack
#
# def change_smallest_value(number_stack):
#     list1=[]
#     while not number_stack.is_empty():
#         list1.append(number_stack.pop())
#
#     l=min(list1)
#     l1=[]
#     l2=[]
#     for i in list1: