added code in python (#19274)

* added code in python

Added bubble sort code in python

* fix: code formatting
pull/19341/head
RujutaKelkar 2018-10-16 00:22:30 +05:30 committed by Aditya
parent 9ce249489d
commit 15319692b5
1 changed files with 15 additions and 0 deletions

View File

@ -142,6 +142,21 @@ func bubbleSort(_ inputArray: [Int]) -> [Int] {
}
return numbers // return the sorted array
}
```
### Example in Python
```py
def bubblesort( A ):
for i in range( len( A ) ):
for k in range( len( A ) - 1, i, -1 ):
if ( A[k] < A[k - 1] ):
swap( A, k, k - 1 )
def swap( A, x, y ):
tmp = A[x]
A[x] = A[y]
A[y] = tmp
```
### More Information
<!-- Please add any articles you think might be helpful to read before writing the article -->