예제 #1
0
    @staticmethod
    def sort2(data_list):
        for i_index, one in enumerate(data_list):
            min_idx = i_index
            for j_index, j_one in enumerate(data_list[i_index:], i_index):
                if j_one < data_list[min_idx]:
                    min_idx = j_index
            data_list[i_index], data_list[min_idx] = data_list[
                min_idx], data_list[i_index]
        return data_list


if __name__ == '__main__':
    test_list = [1, 4, 2, 3, 6, 5]
    print(SelectionSort.sort(test_list))
    test_list = [1, 4, 2, 3, 6, 5]
    print(SelectionSort.sort2(test_list))
    data_size = [10000, 100000]

    for size in data_size:
        input_data = ArrayGenerator.generate_random_array(size, size)
        sort_test("SelectionSort", input_data)
    """
    java
    SelectionSort , n = 10000 : 0.123313 s
    SelectionSort , n = 100000 : 10.184974 s
    
    python
    SelectionSort, size: 10000 : 3.543562889099121 s
    SelectionSort, size: 10000 : 383.543562889099121 s
    """
예제 #2
0
            # if arr == [2, 2, 3, 4, 6, 5]:
            #     print("debug")
            # print(arr)
            arr[j] = t
            # print("end_arr", arr)


if __name__ == '__main__':
    test_list = [6, 4, 2, 3, 1, 5]
    InsertionSort.sort(test_list)
    print(test_list)
    data_size = [10000, 100000]

    for n in data_size:
        # print("Random Array : ")
        # arr = ArrayGenerator.generate_random_array(n, n)
        # arr2 = copy.deepcopy(arr)
        # print(arr2[:10])
        # sort_test("InsertionSort", arr)
        # sort_test("SelectionSort", arr2)

        print("Ordered Array : ")
        arr = ArrayGenerator.generate_ordered_array(n)
        arr2 = copy.deepcopy(arr)
        print(arr2[:10])
        sort_test("InsertionSort", arr)
        sort_test("SelectionSort", arr2)
        """
        InsertionSort, size: 10000 : 0.009609222412109375 s
        SelectionSort, size: 10000 : 3.472014904022217 s
        """
예제 #3
0
    def sort(data_list):
        for i in range(len(data_list)):
            for j in range(1, i + 1)[::-1]:
                if data_list[j] < data_list[j - 1]:
                    data_list[j -
                              1], data_list[j] = data_list[j], data_list[j - 1]


if __name__ == '__main__':
    test_list = [6, 4, 2, 3, 1, 5]
    InsertionSort.sort(test_list)
    print(test_list)
    data_size = [10000, 100000]

    for size in data_size:
        input_data = ArrayGenerator.generate_random_array(size, size)
        sort_test("InsertionSort", input_data)
    """
    java:
    SelectionSort , n = 10000 : 0.103108 s
    SelectionSort , n = 100000 : 10.020195 s
    InsertionSort , n = 10000 : 0.157813 s
    InsertionSort , n = 100000 : 15.633680 s
    
    python:
    SelectionSort, size: 10000 : 3.543562889099121 s
    SelectionSort, size: 10000 : 383.543562889099121 s
    
    
    """
예제 #4
0
                arr[k] = temp[j - l]
                j = j + 1


if __name__ == '__main__':
    import ArrayGenerator, SortingHelper

    data = ArrayGenerator.ArrayGenerator.generate_random_array(10, 10)
    SortingHelper.sort_test("MergeSort", data)
    from SortingHelper import sort_test
    data_size = [10000, 100000]

    for size in data_size:
        input_data = ArrayGenerator.ArrayGenerator.generate_random_array(
            size, size)
        sort_test("SelectionSort", input_data)
        input_data = copy.deepcopy(input_data)
        sort_test("InsertionSort", input_data)
        input_data = copy.deepcopy(input_data)
        sort_test("MergeSort", input_data)
    """
    MergeSort, size: 10 : 0.009989738464355469 s
SelectionSort, size: 10000 : 5.314520597457886 s
InsertionSort, size: 10000 : 0.009989738464355469 s
MergeSort, size: 10000 : 82.484299659729 s


SelectionSort, size: 10000 : 3.6478559970855713 s
InsertionSort, size: 10000 : 0.010154008865356445 s
MergeSort, size: 10000 : 47.00605630874634 s
    """
예제 #5
0
    data = ArrayGenerator.ArrayGenerator.generate_random_array(10, 10)
    data = [1, 3, 4, 5, 2, 7, 6]
    SortingHelper.sort_test("MergeSort", data)
    data = copy.deepcopy(data)
    SortingHelper.sort_test("MergeSort2", data)

    from SortingHelper import sort_test

    #
    data_size = [10000]
    # #
    for size in data_size:
        input_data = ArrayGenerator.ArrayGenerator.generate_random_array(size, size)
        input_data = copy.deepcopy(input_data)
        sort_test("MergeSort", input_data)
        input_data = copy.deepcopy(input_data)
        sort_test("MergeSort2", input_data)

        """
        MergeSort, size: 10000 : 10.9449942111969 s
        MergeSort2, size: 10000 : 0.01164698600769043 s
        """
    #
        input_data = ArrayGenerator.ArrayGenerator.generate_ordered_array(size)
        input_data = copy.deepcopy(input_data)
        sort_test("MergeSort", input_data)
        input_data = copy.deepcopy(input_data)
        sort_test("MergeSort2", input_data)

        """