You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
584 B

  1. # Python program for implementation of Selection
  2. # Sort
  3. import sys
  4. A = [64, 25, 12, 22, 11]
  5. # Traverse through all array elements
  6. for i in range(len(A)):
  7. # Find the minimum element in remaining
  8. # unsorted array
  9. min_idx = i
  10. for j in range(i+1, len(A)):
  11. if A[min_idx] > A[j]:
  12. min_idx = j
  13. # Swap the found minimum element with
  14. # the first element
  15. A[i], A[min_idx] = A[min_idx], A[i]
  16. # Driver code to test above
  17. print ("Sorted array")
  18. for i in range(len(A)):
  19. print("%d" %A[i]),