MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / maxIndex

Function maxIndex

divideAndConquer.py:5–17  ·  view source on GitHub ↗
(alist, start, end)

Source from the content-addressed store, hash-verified

3'''
4# 分治算法实现查找数组中的最大元素的位置
5def maxIndex(alist, start, end):
6 if start > end or len(alist) == 0:
7 return
8 pivot = (start+end) >> 1
9 if end - start == 1:
10 return start
11 else:
12 temp1 = maxIndex(alist, start, pivot)
13 temp2 = maxIndex(alist, pivot, end)
14 if alist[temp1] < alist[temp2]:
15 return temp2
16 else:
17 return temp1
18print(maxIndex([5,7,9,3,4,8,6,2,0,1], 0, 9))
19
20# 分治法计算正整数幂

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected