FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms/sort/bubble_sort.py at master · BeFreeB/algorithms · GitHub
BeFreeB
/
algorithms
Public
forked from
keon/algorithms
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms
/
sort
/
bubble_sort.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (20 loc) · 533 Bytes
Breadcrumbs
algorithms
/
sort
/
bubble_sort.py
Copy path
File metadata and controls
28 lines (20 loc) · 533 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
https://en.wikipedia.org/wiki/Bubble_sort
Worst-case performance: O(N^2)
"""
def
bubble_sort
(
arr
):
def
swap
(
i
,
j
):
arr
[
i
],
arr
[
j
]
=
arr
[
j
],
arr
[
i
]
n
=
len
(
arr
)
swapped
=
True
while
swapped
:
swapped
=
False
for
i
in
range
(
1
,
n
):
if
arr
[
i
-
1
]
>
arr
[
i
]:
swap
(
i
-
1
,
i
)
swapped
=
True
array
=
[
1
,
5
,
65
,
23
,
57
,
1232
,
-
1
,
-
5
,
-
2
,
242
,
100
,
4
,
423
,
2
,
564
,
9
,
0
,
10
,
43
,
64
,
32
,
1
,
999
]
print
(
array
)
bubble_sort
(
array
)
print
(
array
)
Back
|
FazBrowse Home
|
New Git URL