MCPcopy Create free account
hub / github.com/geekcomputers/Python / bubbleSort

Function bubbleSort

Sorting Algorithms/bubblesortpgm.py:26–41  ·  view source on GitHub ↗
(arr)

Source from the content-addressed store, hash-verified

24
25
26def bubbleSort(arr):
27 n = len(arr)
28
29 # Traverse through all array elements
30 for i in range(n):
31 not_swap = True
32 # Last i elements are already in place
33 for j in range(0, n - i - 1):
34 # traverse the array from 0 to n-i-1
35 # Swap if the element found is greater
36 # than the next element
37 if arr[j] > arr[j + 1]:
38 arr[j], arr[j + 1] = arr[j + 1], arr[j]
39 not_swap = False
40 if not_swap:
41 break
42
43
44# Driver code to test above

Callers 1

bubblesortpgm.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected