-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminMax.py
More file actions
48 lines (38 loc) · 1012 Bytes
/
minMax.py
File metadata and controls
48 lines (38 loc) · 1012 Bytes
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
def findSmallest(arr):
smallest=arr[0]
smallest_index=0
for i in range(1,len(arr)):
if arr[i] < smallest:
smallest=arr[i]
smallest_index=i
return smallest_index
def findBiggest(arr):
biggest=arr[0]
biggest_index=0
for i in range(1,len(arr)):
if arr[i] > biggest:
biggest=arr[i]
biggest_index=i
return biggest_index
def selectionSort(arr):
newArr=[]
for i in range(int(len(arr)/2)):
smallest = findSmallest(arr)
newArr.append(arr.pop(smallest))
biggest = findBiggest((arr))
newArr.append(arr.pop(biggest))
return newArr
print(selectionSort([10, 4, 2, 6, 5, 8, 7, 1, 3, 9]))
# def selectionSort(arr):
# newArr=[]
# for i in range(int(len(arr)/2)):
# minn=min(arr)
# newArr.append(minn)
# arr.remove(minn)
# maxx=max(arr)
# newArr.append(maxx)
# arr.remove(maxx)
#
# return newArr
#
# print(selectionSort([10, 4, 2, 6, 5, 8, 7, 1, 3, 9]))