File tree 1 file changed +37
-0
lines changed
Algorithms/Sorting Algorithms 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Wed Aug 29 12:55:58 2018
5
+
6
+ @author: avinash
7
+ """
8
+
9
+
10
+ def partition (lst , low , high ):
11
+ i = low - 1
12
+ pivot = lst [high ]
13
+ for j in range (low , high ):
14
+ if lst [j ] <= pivot :
15
+ i += 1
16
+ lst [i ], lst [j ] = lst [j ], lst [i ]
17
+ lst [i + 1 ], lst [high ] = lst [high ], lst [i + 1 ]
18
+ return i + 1
19
+
20
+
21
+ def quick_sort (lst , low , high ):
22
+ if low < high :
23
+ pi = partition (lst , low , high )
24
+ quick_sort (lst , low , pi - 1 )
25
+ quick_sort (lst , pi + 1 , high )
26
+
27
+
28
+ lst = []
29
+ size = int (input ("Enter size of the list: \t " ))
30
+ for i in range (size ):
31
+ element = int (input ("Enter an element: \t " ))
32
+ lst .append (element )
33
+
34
+ low = 0
35
+ high = len (lst ) - 1
36
+ quick_sort (lst , low , high )
37
+ print ("The sorted list: \t " , lst )
You can’t perform that action at this time.
0 commit comments