File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Selection sort is a sorting function that finds the minimum element
2+ # from the unsorted part of the array(i.e right) and moves it to the
3+ # sorted part the array(i.e left)
4+
5+ def selectionSort (arr ):
6+ for i in range (len (arr )- 1 ):
7+ #initially we take i as index that has the minimum value
8+ min = i
9+ #then we search the part of the array after this index
10+ for j in range (i + 1 , len (arr )):
11+ #if we find an index whose value is less than that at min then
12+ if arr [j ]< arr [min ]:
13+ #we assign this index as the index that has the minimum value
14+ min = j
15+ #after the this loop we place the element at min index at its respective position
16+ arr [min ], arr [i ] = arr [i ], arr [min ]
17+
18+ A = list (map (int , input ('Please enter your array:\n ' ).split ())) #enter array as space separated integers
19+ print ('\n The array after selection sort is: \n ' )
20+ selectionSort (A )
21+ print (A )
22+
You can’t perform that action at this time.
0 commit comments