added code in python (#19274)
* added code in python Added bubble sort code in python * fix: code formattingpull/19341/head
parent
9ce249489d
commit
15319692b5
|
@ -142,6 +142,21 @@ func bubbleSort(_ inputArray: [Int]) -> [Int] {
|
||||||
}
|
}
|
||||||
return numbers // return the sorted array
|
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
|
### More Information
|
||||||
<!-- Please add any articles you think might be helpful to read before writing the article -->
|
<!-- Please add any articles you think might be helpful to read before writing the article -->
|
||||||
|
|
Loading…
Reference in New Issue