Advertisement
makispaiktis

Quicksort Method in Python

Mar 15th, 2020 (edited)
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. def quicksort(matrix):
  2.     for i in range(0, len(matrix)):
  3.         for j in range(i, len(matrix)):
  4.             if matrix[i] > matrix[j]:
  5.                 # Swap syntax in Java
  6.                 matrix[i], matrix[j] = matrix[j], matrix[i]
  7.     return matrix
  8.  
  9. # MAIN FUNCTION
  10. matrixA  = [1, 3, 4, 10, 7, 2, 9, 8, 5, 6]
  11. print(quicksort(matrixA))
  12. matrixB  = [1, 3, 4, 10, 7, 2, 9, 8, 2, 8, 5, 6]
  13. print(quicksort(matrixB))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement