arr=[] while True: #输入数据 当输入q结束 a=raw_input() if a=="q": break arr.append(int(a)) s=len(arr) for i in range(s): #冒泡排序 for j in range(s-i-1): if arr[j]>arr[j+1]: arr[j],arr[j+1]=arr[j+1],arr[j] print arr for i in range(s): #选择排序 k=i for j in r…
快排算法很经典,今天用scala的函数式思维来整理一下并实现: def qsort(list: List[Int]):List[Int]=list match { case Nil=>Nil case ::(pivot,t)=>qsort(t.filter(_<=pivot)) ++ List(pivot) ++ qsort(t.filter(_>pivot)) } println(qsort(List(1,32,4,5,2,3,5,6,7,33))) ** ok ** 以下是C语…