(alist, start, end)
| 3 | ''' |
| 4 | # 分治算法实现查找数组中的最大元素的位置 |
| 5 | def 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 |
| 18 | print(maxIndex([5,7,9,3,4,8,6,2,0,1], 0, 9)) |
| 19 | |
| 20 | # 分治法计算正整数幂 |