예제 #1
0
def merge_stack(stack1, stack2):
    #Remove pass and write your logic here
    list1 = []
    output_stack = Stack(stack1.get_max_size() + stack2.get_max_size())
    while (not (stack1.is_empty())):
        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
예제 #2
0
def separate_boxes(box_stack):
    #Remove pass and write your logic here
    new_queue = Queue(box_stack.get_max_size())
    mod_stack = Stack(box_stack.get_max_size())
    while (not (box_stack.is_empty())):
        data = box_stack.pop()
        if (data == "Red" or data == "Green" or data == "Blue"):
            mod_stack.push(data)
        else:
            new_queue.enqueue(data)
    while (not (mod_stack.is_empty())):
        a = mod_stack.pop()
        box_stack.push(a)
    return (new_queue)
예제 #3
0
def merge_stack(stack1, stack2):
    new_stack = Stack(stack1.get_max_size() + stack2.get_max_size())
    list1 = []
    while not stack1.is_empty():
        list1.append(stack1.pop())

    while not stack2.is_empty():
        list1.append(stack2.pop())

    list1.sort()

    while not new_stack.is_full():
        new_stack.push(list1.pop(0))

    return new_stack
예제 #4
0
    #Remove pass and write your logic here
    list1 = []
    output_stack = Stack(stack1.get_max_size() + stack2.get_max_size())
    while (not (stack1.is_empty())):
        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()
예제 #5
0
    i = 0
    while (i < len(list2)):
        if (list2[i] == 1):
            list1.append(list1[0])
            list1.pop(0)
            print(list1)
        elif (list2[i] == 2):
            list1.insert(0, list1[-1])
            list1.pop(-1)
        i = i + 1
    for i in list1:
        output_queue.enqueue(i)
    #Write your code here
    return output_queue


#You may modify the below code for testing
input_stack = Stack(4)
input_stack.push(2)
input_stack.push(1)
input_stack.push(2)
input_stack.push(1)

input_queue = Queue(5)
input_queue.enqueue('X')
input_queue.enqueue('a')
input_queue.enqueue('b')
input_queue.enqueue('c')

output_queue = queue_ordering(input_queue, input_stack)
output_queue.display()
예제 #6
0
    return new_queue


#     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:")
예제 #7
0
            l2.append(i)
#     print(l1)
#     print(l2)
    l2.reverse()

    m = []
    m = l1 + l2
    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=[]
예제 #8
0
 def __init__(self,ball_stack):
     self.ball_container=ball_stack
     self.red_balls_container=Stack(2)
     self.green_balls_container = Stack(2)
     self.blue_balls_container = Stack(2)
     self.yellow_balls_container = Stack(2)
예제 #9
0
                    a = ball
                else:
                    b = ball
            self.blue_balls_container.push(b)
            self.blue_balls_container.push(a)
    def display_ball_details(self,color):
        pass

#Use different values to test your program
ball1=Ball("Red","A")
ball2=Ball("Blue","B")
ball3=Ball("Yellow","B")
ball4=Ball("Blue","A")
ball5=Ball("Yellow","A")
ball6=Ball("Green","B")
ball7=Ball("Green","A")
ball8=Ball("Red","B")
ball_list=Stack(8)
ball_list.push(ball1)
ball_list.push(ball2)
ball_list.push(ball3)
ball_list.push(ball4)
ball_list.push(ball5)
ball_list.push(ball6)
ball_list.push(ball7)
ball_list.push(ball8)

#Create objects of Game class, invoke the methods and test the program
g1 = Game(ball_list)
g1.grouping_based_on_color()
g1.display_ball_details("Green")