forked from ambujraj/hacktoberfest2018
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ambujraj#30 from ahmadjaved97/master
Added bubble_sort.py
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
print('Enter the number of terms: ') | ||
num = int(input()) | ||
|
||
alist = [] | ||
|
||
for i in range(0, num): | ||
if(i == 0): | ||
alist.append(0) | ||
elif(i == 1): | ||
alist.append(1) | ||
else: | ||
alist.append(alist[i - 1] + alist[i - 2]) | ||
|
||
print('The fibonnaci series is: ') | ||
for i in range(num): | ||
print(alist[i], end = ' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def bubbleSort(alist): | ||
for passnum in range(len(alist)-1, 0, -1): | ||
for i in range(passnum): | ||
if alist[i] > alist[i+ 1]: | ||
alist[i], alist[i+1] = alist[i+1], alist[i] | ||
|
||
|
||
alist = [] | ||
print('Enter the elements to be sorted: ') | ||
alist = list(map(int,input().split())) | ||
|
||
bubbleSort(alist) | ||
|
||
print('Sorted list is: ') | ||
|
||
for i in range(len(alist)): | ||
print(alist[i], end = ' ') | ||
|