Пример #1
0
    minv = test_list[1]
    maxv = -10000000000
    for x in test_list[2:]:
        tmp_max = x - minv
        if tmp_max > maxv:
            maxv = tmp_max
        if x < minv:
            minv = x
    print(maxv)


testOne = [6, 5, 3, 1, 3, 4, 3]
testTwo = [3, 4, 3, 2]
testThree = [7, 3, 2, 4, 1, 5, 3, 6]
testFour = [2, 100000, 1]
testFive = list(map(int, ImportCase.autoinput_returnlist("ALDS1_1Short.txt")))

# Algorithms1での実行 O(n^2)
start_time = time.time()
output_max_One(testOne)
output_max_One(testTwo)
output_max_One(testThree)
output_max_One(testFour)
output_max_One(testFive)
print(time.time() - start_time)

# Algorithm2での実行 O(n)
start_time = time.time()
output_max_Two(testOne)
output_max_Two(testTwo)
output_max_Two(testThree)
Пример #2
0
    while secondv_j < end:
        # xより小さい場合の処理.大きい場合はjを進めるだけ.
        if v[secondv_j] <= endval:
            firstv_i += 1
            v[firstv_i], v[secondv_j] = v[secondv_j], v[firstv_i]
        secondv_j += 1
    v[firstv_i + 1], v[end] = v[end], v[firstv_i + 1]
    print(v)
    return firstv_i + 1


test_listOne = [3, 2, 4, 1]
test_listTwo = [10, 8, 4, 19, 2, 20, 5]
test_listThree = list(range(1, 101))
test_listFour = list(
    map(int, ImportCase.autoinput_returnlist("ALDS1_1Short.txt")))
test_listFive = [4, 8, 9, 1, 10, 6, 2, 5, 3, 7]
test_listSix = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11]
# 1000行のデータ:
# 挿入ソート:0.31秒.
# バブルソート:0.45秒
# 選択ソート:0.44秒
# マージソート:0.012秒

#start_time = time.time()
#mergesort(test_listFour, 0, len(test_listFour))
#print(test_listFour)
#print(time.time() - start_time)

print(partition(test_listSix, 0, len(test_listSix) - 1))