Update bubble_sort.md
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
bubble sort also makes it too simple for sorting any list or array. It simply compares the two neighbouring values and swap them.
|
bubble sort also makes it too simple for sorting any list or array. It simply compares the two neighbouring values and swap them.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def bubbleSort(arr):
|
def bubble_sort(arr):
|
||||||
for passnum in range(len(arr)-1,0,-1):
|
for passnum in range(len(arr)-1,0,-1):
|
||||||
for i in range(passnum):
|
for i in range(passnum):
|
||||||
if arr[i]>arr[i+1]:
|
if arr[i]>arr[i+1]:
|
||||||
@ -15,6 +15,6 @@ def bubbleSort(arr):
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
arr = [54,26,93,17,77,31,44,55,20]
|
arr = [54,26,93,17,77,31,44,55,20]
|
||||||
bubbleSort(arr)
|
bubble_sort(arr)
|
||||||
print("sorted %s" %arr) # sorted via bubble sort
|
print("sorted %s" %arr) # [17,20,26,31,44,54,55,77,91]
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user