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 d14fd7f

Browse files
python algorithms
0 parents commit d14fd7f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## BUBBLE SORT - SORTING ALGORITHMS
2+
3+
- 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" />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Bubble sort example
2+
3+
def bubbleSortAlgorithm(arr):
4+
# for every element (arranged backwards)
5+
for n in range(len(arr)-1, 0, -1): # [20,19,18,17 .... 0]
6+
for k in range(n):
7+
if arr[k] > arr[k+1]:
8+
temp = arr[k]
9+
arr[k] = arr[k+1]
10+
arr[k+1] = temp
11+
12+
return arr
13+
14+
arr = [3,2,13,4,6,5,7,8,20]
15+
print("Output: ", bubbleSortAlgorithm(arr))

0 commit comments

Comments
(0)

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