FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
interview_python/DS-using-python/bubblesort at master · lccl7/interview_python · GitHub
lccl7
/
interview_python
Public
forked from
taizilongxu/interview_python
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
interview_python
/
DS-using-python
/
bubblesort
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (30 loc) · 750 Bytes
Breadcrumbs
interview_python
/
DS-using-python
/
bubblesort
Copy path
File metadata and controls
37 lines (30 loc) · 750 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
29
30
31
32
33
34
35
36
37
L1 = [5, 2, 7, 4, 6, 3, 1]
def bubblesort1(seq):
print(seq)
n = len(seq)
itr1= 0
while(n > 1):
for j in range(n-1):
if seq[j] > seq[j+1]:
seq[j], seq[j+1] = seq[j+1], seq[j]
itr1= itr1+ 1
print("iter: %d " %itr1)
print(seq)
n = n-1
bubblesort1(L1)
L2 = [5, 2, 7, 4, 6, 3, 1]
def bubblesort2(seq):
print(seq)
iSorted = False
n = len(seq)
itr2 = 0
while(iSorted == False):
iSorted = True
for i in range(n-1):
if seq[i] > seq[i+1]:
seq[i], seq[i+1] = seq[i+1], seq[i]
iSorted = False
itr2 = itr2+ 1
print("iter: %d" %itr2)
print(seq)
bubblesort2(L2)
Back
|
FazBrowse Home
|
New Git URL