File tree Expand file tree Collapse file tree 2 files changed +13
-16
lines changed
chapters/sorting_searching/bubble Expand file tree Collapse file tree 2 files changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
16
16
[ import:3-21, lang:"c_cpp"] ( code/c/bubble_sort.c )
17
17
{% sample lang="js" %}
18
18
[ import:1-11, lang:"javascript"] ( code/js/bubble.js )
19
+ {% sample lang="py" %}
20
+ [ import:5-10, lang:"python"] ( code/python/bubblesort.py )
19
21
{% sample lang="hs" %}
20
22
[ import, lang:"haskell"] ( code/haskell/bubbleSort.hs )
21
23
{% sample lang="cpp" %}
Original file line number Diff line number Diff line change 1
- #!usr/bin/python3
2
-
3
- #import section
1
+ from __future__ import print_function
4
2
import random
5
3
6
4
7
5
def bubble_sort (array ):
8
- len_array = len (array )
9
- for i in range (len_array ):
10
- for j in range (len_array - i - 1 ):
11
- if (array [j ] > array [j + 1 ]):
12
- array [j ], array [j + 1 ] = array [j + 1 ], array [j ] #swap elements in the list
13
-
6
+ len_array = len (array )
7
+ for i in range (len_array ):
8
+ for j in range (len_array - i - 1 ):
9
+ if (array [j ] > array [j + 1 ]):
10
+ array [j ], array [j + 1 ] = array [j + 1 ], array [j ] #swap elements in the list
14
11
15
12
def main ():
16
- number = [random .randint (0 , 10000 ) for _ in range (10 )]
17
- print ("Before Sorting {}" .format (number ))
18
- bubble_sort (number )
19
- print ("After Sorting {}" .format (number ))
20
-
13
+ number = [random .randint (0 , 1000 ) for _ in range (10 )]
14
+ print ("Before Sorting {}" .format (number ))
15
+ bubble_sort (number )
16
+ print ("After Sorting {}" .format (number ))
21
17
22
- if __name__ == "__main__" :
23
- main ()
18
+ main ()
You can’t perform that action at this time.
0 commit comments