Skip to content

Commit

Permalink
Create sel.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nayan5 authored Oct 18, 2023
1 parent a395d4a commit 6572fbb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Selection Sort algorithm in Python
def selectionSort(array, size):

for s in range(size):
min_idx = s

for i in range(s + 1, size):

# For sorting in descending order
# for minimum element in each loop
if array[i] < array[min_idx]:
min_idx = i

# Arranging min at the correct position
(array[s], array[min_idx]) = (array[min_idx], array[s])

# Driver code
data = [ 7, 2, 1, 6 ]
size = len(data)
selectionSort(data, size)

print('Sorted Array in Ascending Order is :')
print(data)

0 comments on commit 6572fbb

Please sign in to comment.