@liuximing
2018-04-10T18:53:00.000000Z
字数 1193
阅读 135
Python

#/usr/bin/python# -*- coding: UTF-8 -*-##pip install numpy#pip install scipy#pip install matplotlibimport matplotlib.pyplot as pltimport numpy as npx = np.linspace(1, 100, 10)y1 = np.power(x, 2)plt.plot(x, y1, 'r-o', label='n^2')y2 = np.multiply(x, np.log2(x))plt.plot(x, y2, 'g-^', label='nlog2n')y2 = np.multiply(x, np.log(x))plt.plot(x, y2, 'b-+', label='nlogn')plt.legend()plt.xlabel('nums')plt.ylabel('time')plt.title('mean time complexity')plt.show()
def bubble_sorts(list):count = len(list)for i in range(0, count-1):for j in range(0, count-1-i):if list[j] > list[j+1]:list[j], list[j+1] = list[j+1], list[j]return list
def select_sort(list):count = len(list)for i in range(0, count - 1):max = 0for j in range(0, count - 1 - i):if list[max] < list[j + 1]:max = j + 1list[max], list[count - 1 - i] = list[count - 1 - i], list[max]return list
def insert_sort(list):count = len(list)for i in range(1, count):current = list[i]pos = iwhile pos > 0 and list[pos - 1] > current:list[pos] = list[pos - 1]pos = pos - 1list[pos] = currentreturn list
def shell_sort(list):count = len(list)step = count / 2while step > 0:for i in range(step, count):current = list[i]pos = iwhile pos > 0 and list[pos - step] > current:list[pos] = list[pos - step]pos = pos - steplist[pos] = currentstep = step / 2return list