Python programming binary method for bubble Algorithm + quick sorting code example, python binary method
The example in this article is mainly the Python programming binary method for implementing the bubble Algorithm + quick sorting. The details are as follows.
Bubble algorithm:
#-*-Coding: UTF-8-*-# bubble sort def func (lt): if type (lt). _ name __! = 'LIST' and type (lt). _ name __! = 'Tuple': returnif type (lt ). _ name _ = 'tuple': return list (lt) for I in range (1, len (lt)-1): for j in range (1, len (lt)-I): if lt [j]> lt [j + 1]: lt [j], lt [j + 1] = lt [j + 1], lt [j] return ltlt_01 = [,] print func (lt_01)
========================================================== ==========
Bipartite method: (implemented through recursive function call)
def func(lt=[]): if type(lt).__name__ !='list' and type(lt).__name__!='tuple': return if type(lt).__name__ =='tuple': return list(lt) if len(lt)<=1: return lt k = lt[0] lt_l = [] lt_r = [] lt_m = [] for i in lt: if i>k: lt_r.append(i) elif i<k: lt_l.append(i) else: lt_m.append(i) lt_l=func(lt_l) lt_r=func(lt_r) return lt_l + lt_m + lt_ra = [2,4,12,6,23,16,28]print func(a)
Summary
The above is all the content of this article on the Python programming binary method for implementing the bubble Algorithm + Quick Sort code sample. I hope it will be helpful to you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!