File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ from __future__ import print_function
2+
3+ def quick_sort_3partition (sorting , left , right ):
4+ if right <= left :
5+ return
6+ a = i = left
7+ b = right
8+ pivot = sorting [left ]
9+ while i <= b :
10+ if sorting [i ] < pivot :
11+ sorting [a ], sorting [i ] = sorting [i ], sorting [a ]
12+ a += 1
13+ i += 1
14+ elif sorting [i ] > pivot :
15+ sorting [b ], sorting [i ] = sorting [i ], sorting [b ]
16+ b -= 1
17+ else :
18+ i += 1
19+ quick_sort_3partition (sorting , left , a - 1 )
20+ quick_sort_3partition (sorting , b + 1 , right )
21+
22+ if __name__ == '__main__' :
23+ try :
24+ raw_input # Python 2
25+ except NameError :
26+ raw_input = input # Python 3
27+
28+ user_input = raw_input ('Enter numbers separated by a comma:\n ' ).strip ()
29+ unsorted = [ int (item ) for item in user_input .split (',' ) ]
30+ quick_sort_3partition (unsorted ,0 ,len (unsorted )- 1 )
31+ print (unsorted )
You can’t perform that action at this time.
0 commit comments