-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecursivlyMinimumIndex.py
39 lines (35 loc) · 1.33 KB
/
recursivlyMinimumIndex.py
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
def minElementIndex(list,lowerIndex,upperIndex,minIndex):
'''
Objective: To return a index of minimum value of given area in list
Input Parameters :
lowerIndex-> containing the lower index
upperIndex-> containing the upper index
minIndex-> containing the minimum index
Return: index of minimum value
'''
#Approach : Recursive
if(lowerIndex==upperIndex):
return minIndex
elif(lowerIndex<upperIndex):
if(list[minIndex]>list[lowerIndex]):
minIndex=lowerIndex
return minElementIndex(list,lowerIndex+1,upperIndex,minIndex)
else:
return minElementIndex(list,lowerIndex+1,upperIndex,minIndex)
def main():
'''
Objective : To print a index of minimum value of given area in list
Input Parameters :
lowerIndex-> containing the lower index
upperIndex-> containing the upper index
minIndex-> containing the minimum index
'''
# Approach : Call the function minElementIndex()
list=[12,22,65,4,54,8,89,656,98,23]
lowerIndex=0
upperIndex=5
minIndex=5
minIndex=minElementIndex(list,lowerIndex,upperIndex,minIndex)
print("Minimum Index Is : ",minIndex," and its value is: ",list[ minIndex])
if __name__ == '__main__':
main()