File tree 2 files changed +17
-22
lines changed
2 files changed +17
-22
lines changed Original file line number Diff line number Diff line change 1
- <h1 >sorting_algorithms_python</h1 >
2
- <br >
3
- Sort algorithms implemented in Python.
4
- <br ><br ><br >
5
- Bubble<br >
6
- Insertion<br >
7
- Selection<br >
8
- Quick<br >
9
- Merge<br >
10
- Shell<br >
11
- Heap<br >
12
- Counting<br >
13
- Radix<br >
14
- Bucket<br >
15
- Gnome<br >
16
- Comb<br >
17
- Cocktail<br >
1
+ # Sorting Algorithms in Python
2
+
3
+
4
+ This is just a demonstration of the implementation of some sorting algorithms using Python. There are implementations of
5
+ sorting in Python's standard library that are much better for performance reasons.
6
+ When I wrote these codes I was learning Python and I wanted to do some exercises to improve my Python skills and then
7
+ since I was taking Data Structures classes in college I implemented the algorithms in Python, I already knew the most
8
+ well-known sort algorithms, but I ended up getting myself excited and learning a few more as was the case with Comb,
9
+ Gnome Cocktail and Shell Sort.
Original file line number Diff line number Diff line change @@ -14,15 +14,18 @@ def bubble(nlist):
14
14
if size <= 1 :
15
15
return nlist
16
16
17
- exchanges = True
17
+ swapped = True
18
18
19
19
for i in range (size ):
20
- if not exchanges : break
21
- exchanges = False
20
+ if not swapped :
21
+ break
22
+
23
+ swapped = False
24
+
22
25
for j in range (size - i ):
23
26
if nlist [j ] > nlist [j + 1 ]:
24
- nlist [j + 1 ], nlist [j ] = nlist [j ], nlist [j + 1 ]
25
- exchanges = True
27
+ nlist [j + 1 ], nlist [j ] = nlist [j ], nlist [j + 1 ]
28
+ swapped = True
26
29
27
30
return nlist
28
31
You can’t perform that action at this time.
0 commit comments