changing-array-to-list

This commit is contained in:
vignesh
2018-04-14 08:35:58 +05:30
parent d3c9524379
commit 841385b5ed
9 changed files with 45 additions and 45 deletions

View File

@ -2,18 +2,18 @@
Bubble_sort uses the technique of comparing and swapping
```python
def bubble_sort(arr):
for passnum in range(len(arr) - 1, 0, -1):
def bubble_sort(lst):
for passnum in range(len(lst) - 1, 0, -1):
for i in range(passnum):
if arr[i] > arr[i + 1]:
temp = arr[i]
arr[i] = arr[i + 1]
arr[i + 1] = temp
if lst[i] > lst[i + 1]:
temp = lst[i]
lst[i] = lst[i + 1]
lst[i + 1] = temp
```
```python
arr = [54,26,93,17,77,31,44,55,20]
bubble_sort(arr)
print("sorted %s" %arr) # [17,20,26,31,44,54,55,77,91]
lst = [54,26,93,17,77,31,44,55,20]
bubble_sort(lst)
print("sorted %s" %lst) # [17,20,26,31,44,54,55,77,91]
```