Beispiel #1
0
    def DS_stack(self):
        try:
            length = int(input(" Enter the length of your Stack: "))
        except:
            return self.DS_stack()

        # Stack instantiation with the given length
        stack = Stack(length)

        while True:
            print(
                '\n [STACK OPERATIONS] \n\n 1. Push\n 2. Pop\n 3. Display\n 4. Count\n 5. Back\n'
            )

            try:
                selectedNumber = int(input("Select a number: "))
            except:
                print("\nPlease enter a valid input\n")
                input("Press [Enter] to continue...")
                self.DS_stack()

            if selectedNumber == 1:
                value = int(input(" Enter the value that you want to push: "))
                stack.push(value)
                print("Success!")
                input("Press [Enter] to continue...")

            elif selectedNumber == 2:
                stack.pop()
                print("Success!")
                input("Press [Enter] to continue...")

            elif selectedNumber == 3:
                stack.display()
                input("Press [Enter] to continue...")

            elif selectedNumber == 4:
                stack.count()
                input("Press [Enter] to continue...")

            elif selectedNumber == 5:
                self.DS_main()

            else:
                print(
                    "The number you entered is not in the choices... Going back to the main screen instead..."
                )
                input("Press [Enter] to continue...")
                self.DS_main()
Beispiel #2
0
#DSA-Assgn-13

#This assignment needs DataStructures.py file in your package, you can get it    from resources page

from DataStructures import Stack


def change_smallest_value(number_stack):
    #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()
Beispiel #3
0
        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


#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()