1234567891011121314151617181920212223242526272829 |
- def bubsort(l):
- """ Tri pas la méthode des bulles
-
- Exemples:
-
- >>> bubsort([4,3,5])
- [3, 4, 5]
- >>> bubsort(["abc","aa","cdef", "a"])
- ['a', 'aa', 'abc', 'cdef']
- """
- def fmin(ll):
- minv = ll[0]
- ind =0
- lr=len(ll)
- for x in range(1,lr):
- if ll[x]<minv:
- ind =x
- minv=ll[x]
- return ind
- #
- lc= l.copy()
- res= []
- while len(lc)>0:
- ind=fmin(lc)
- res.append(lc.pop(ind))
- return res
|