elif user_choice == 'i':
        context.set_strategy(first_strategy)
        print('Strategy 1 chosen')

    elif user_choice == 'f':
        context.set_strategy(second_strategy)
        print('Strategy 2 chosen')

    elif user_choice == 'g':
        print_dict(list_dict)
        chosen = input('Enter the number of the list you want to edit: ')
        if chosen in list_dict:
            position = input('Enter position to insert new values: ')
            param = input('Enter the value of the parameter: ')
            new_list = context.generate(list_dict[chosen], position, param)
            if new_list is not False:
                print('New list:', new_list)
                list_dict[chosen] = new_list
        else:
            print('We have only list 1 and list 2')

    elif user_choice == 's':
        print_dict(list_dict)

    elif user_choice == 'd':
        print_dict(list_dict)
        chosen = input('Enter the number of the list you want to edit: ')
        if chosen in list_dict:
            position = input('Enter position to delete an element: ')
            if list_dict[chosen].remove_at(position):
Example #2
0
def main():
    first_list = LinkedList()
    second_list = LinkedList()
    list_dict = {1: first_list,
                 2: second_list}
    first_strat = StrategyOne()
    second_strat = StrategyTwo()
    strategy_to_use = Context()
    option = int(menu_ui())
    while option != 8:
        # print("Option is", option)
        if option == 1:
            strategy_to_use.set_strategy(first_strat)
            print("Using first strategy")

        elif option == 2:
            strategy_to_use.set_strategy(second_strat)
            print("Using second strategy")

        elif option == 3:
            # print("\noption 3\n")
            list_choice = list_choice_func()
            position = input('Enter position to insert new values: ')
            data = input('Enter the value of the parameter (amount to generate or name of file): ')
            new_list = strategy_to_use.generate(list_dict[list_choice], position, data)
            if new_list is not False:
                print('New list:')
                new_list.print()
                list_dict[list_choice] = new_list
                # print('New list:')
                # list_dict[list_choice].print()

        elif option == 4:
            list_choice = list_choice_func()
            position = input('Enter position of an element you want to delete: ')
            if list_dict[list_choice].delete_by_position(position):
                print('List with element removed at position', position, "is", list_dict[list_choice])

        elif option == 5:
            list_choice = list_choice_func()
            print("Enter the positions for numbers to be deleted between:")
            start = input("Enter starting position: ")
            end = input("Enter ending position: ")
            list_dict[list_choice].delete_between(start, end)

        elif option == 6:
            print("starting function")
            if list_dict[1].size() == list_dict[2].size():
                N = list_dict[1].size()
                k = input('Enter K:')
                if represents_int(k):
                    k_in_x = list_dict[1].search(k)  # щоб не було матрьошки функцій
                    if list_dict[1].biggest() == int(k):  # працює
                        if len(k_in_x) == 1:  # працює
                            if k_in_x[0] < N // 2:  # працює
                                if list_dict[2].no_positive():
                                    max_in_y = list_dict[2].biggest()
                                    index_of_max_in_y = list_dict[2].search(max_in_y)
                                    if len(index_of_max_in_y) == 1:
                                        list_dict[2].cubing(index_of_max_in_y[0])
                                    else:
                                        print('More than 1 biggest number in list y')
                                else:
                                    print('There are positive number(s) in list y')
                            else:
                                print('k is in the second part of list x', k_in_x[0])
                        else:
                            print('There are more than one k in list x or no k in x')
                    else:
                        print('Biggest element in list x != k, biggest is', list_dict[1].biggest())
                    print('The result list is:')
                    list_dict[2].print()
            else:
                print("lists must be same length")

        elif option == 7:
            if list_dict[1].size() != 0:
                print("First list:")
                list_dict[1].print()
            else:
                print("First list is empty")
            if list_dict[2].size() != 0:
                print("Second list:")
                list_dict[2].print()
            else:
                print("Second list is empty")

        elif option == 8:
            break

        option = int(menu_ui())