Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selection_sort.py Add Selection Sort Algo in Python #528

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions selection_sort/Python/selection_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Python program implementation of Selection Sort

import sys

# Declare static array

Array = [25, 98, 71, 66, 1, 28, 53, 74]

# Traverse through all the elements

for i in range(len(Array)):
# Find minimum element in unsorted array
# Assume index i in minimum and look for minimum element
# in rest of the array. If found change index j is minimum.
min = i
for j in range(i+1, len(Array)):
if Array[min] > Array[j]:
min = j
# Swap the minimum element with the first element
Array[i], Array[min] = Array[min], Array[i]
# Driver Code
print(" Sorted Array: ")
print(Array)