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

Create selection_sort.py #171

Merged
merged 2 commits into from
Oct 7, 2020
Merged
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
27 changes: 27 additions & 0 deletions Selection_Sort/selection_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#funtion for selection sort
def selection_sort(A):
# Traverse through all array elements
for i in range(len(A)):

# Find the minimum element in remaining unsorted array
min_idx=i
for j in range(i+1, len(A)):
if A[min_idx]>A[j]:
min_idx=j

# Swap the found minimum element with the first element
A[i], A[min_idx]=A[min_idx], A[i]
n=int(input("Enter number of element:"))
array=[]
print("Enter array:")
for i in range(0,n):
e=input()
#adding element to array
array.append(e)

#funtion call
selection_sort(array)

print("Sorted array:")
for i in range(len(array)):
print(array[i])