Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 59bad2e

Browse files
Update README.md
1 parent 739f1c3 commit 59bad2e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
## BUBBLE SORT - SORTING ALGORITHMS
22

33
- It sorts two consecutive values ​​in a list and continues this process until the whole list becomes sequential.
4-
<img src="https://www.productplan.com/uploads/bubble-sort-1024x683-2.png" />
4+
5+
```python
6+
def bubbleSortAlgorithm(arr):
7+
# for every element (arranged backwards)
8+
for n in range(len(arr)-1, 0, -1): # [20,19,18,17 .... 0]
9+
for k in range(n):
10+
if arr[k] > arr[k+1]:
11+
temp = arr[k]
12+
arr[k] = arr[k+1]
13+
arr[k+1] = temp
14+
15+
return arr
16+
17+
arr = [3,2,13,4,6,5,7,8,20]
18+
print("Output: ", bubbleSortAlgorithm(arr))
19+
```
20+
output:
21+
```
22+
[2, 3, 4, 5, 6, 7, 8, 13, 20]
23+
```
24+
25+
<img src="https://www.productplan.com/uploads/bubble-sort-1024x683-2.png" />

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /