Skip to content

Instantly share code, notes, and snippets.

@Alfex4936
Created October 24, 2020 10:44
Show Gist options
  • Save Alfex4936/af6a90d0a95c3120bb9292fe33d66558 to your computer and use it in GitHub Desktop.
Save Alfex4936/af6a90d0a95c3120bb9292fe33d66558 to your computer and use it in GitHub Desktop.
Bubble Sort using Cython
def bubbleSort(list array):
return bubbleSort_c(array)
cdef bubbleSort_c(list array):
cdef bint isSorted = False
cdef int count = 0
cdef Py_ssize_t i
cdef Py_ssize_t n = len(array) - 1
while not isSorted:
isSorted = True
for i from 0 <= i < n - count:
if array[i] > array[i + 1]:
array[i], array[i + 1] = array[i + 1], array[i]
isSorted = False
count += 1
return array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment