Algorithm-python for fast sorting (the idea of the binary method) and python for the binary method
Implementation
Store the required numbers in a list.
You will understand:
Implementation Code
1 # coding: UTF-8 2 # Fast sorting. Use the binary algorithm to implement 3 4 5 def quick_sort (list, left, right): 6 if left> right: 7 return 8 temp = list [left] 9 I = left10 j = right11 while I! = J: 12 # first search for 13 while list [j]> = temp and I from the right to the left <j: 14 j-= 115 # search for 16 while list [I] <= temp and I <j: 17 I + = 118 if I <j: 19 t = list [I] 20 list [I] = list [j] 21 list [j] = t22 # Replace the reference number 23 list [left] = list [I] 24 list [I] = temp25 # recursively call 26 quick_sort (list, left, I-1) 27 quick_sort (list, I + 1, right) 28 29 30 while True: 31 list = [] 32 try: 33 num = int (input ('How many do you want to compare? \ N') 34 TB t ValueError: 35 continue36 for k in range (num): 37 a = int (input ('Enter the nth '+ str (k + 1) + 'count: \ n') 38 list. append (a) 39 quick_sort (list, 0, num-1) 40 print ('sorting result: ') 41 for l in range (len (list )): 42 print (list [l], end = '') 43 print ()
Quick sorting is much more efficient than Bubble sorting ~