-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate_mod.py
More file actions
54 lines (40 loc) · 1.07 KB
/
Copy pathcalculate_mod.py
File metadata and controls
54 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def c_to_f(celsius):#摄氏度转华氏度
return celsius*9.0/5+32
def dcsum(a1,n,d):#等差数列求和
return a1*n+n*(n-1)*d/2
def dbsum(a1,n,q):#等比数列求和
return a1*(1-q**n)/(1-q)
def plus(x,y):#x+y
return x + y
def substract(x, y):#x-y
sn = x - y
return sn
def multiplicate(x,y):#x*y
sn = x * y
return sn
def divide(x,y):#x/y
sn = x / y
return sn
def quick(list):#快速排序(比大小)
if list == [] or len(list) == 1:
return list
base = list[0]
left_l, right_l = [], []
for i in list[1:]:
if i >= base:
right_l.append(i)
else:
left_l.append(i)
left_l = quick(left_l)
right_l = quick(right_l)
return left_l + [base] + right_l
def merge_sort(x):#归并排序(比大小)
if len(x) < 2:return x
result,mid = [],int(len(x)/2)
y = merge_sort(x[:mid])
z = merge_sort(x[mid:])
while (len(y) > 0) and (len(z) > 0):
if y[0] > z[0]:result.append(z.pop(0))
else:result.append(y.pop(0))
result.extend(y+z)
return result