mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-07-02 18:46:43 -04:00
Create bubble_sort.py
This commit is contained in:
parent
e1805c9fb5
commit
52cba3f861
1 changed files with 16 additions and 0 deletions
16
sorting/bubble_sort.py
Normal file
16
sorting/bubble_sort.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# author: bt3gl
|
||||||
|
|
||||||
|
|
||||||
|
def bubble_sort(list)
|
||||||
|
|
||||||
|
has_swapped = True
|
||||||
|
|
||||||
|
while has_swapped:
|
||||||
|
has_swapped = False
|
||||||
|
|
||||||
|
for i in range(len(lst) - 1):
|
||||||
|
if lst[i] > lst[i + 1]:
|
||||||
|
lst[i], lst[i + 1] = lst[i + 1], lst[i]
|
||||||
|
has_swapped = True
|
Loading…
Add table
Add a link
Reference in a new issue