美文网首页
Bubble Sort

Bubble Sort

作者: GakkiLove | 来源:发表于2018-04-09 22:59 被阅读0次

Given an array of integers, sort the elements in the array in ascending order. The bubble sort algorithm should be used to solve this problem.

def bubble(array):
  for n in xrange(len(array)-1,0,-1):
    for i in xrange(n):
      if array[i] > array[i+1]:
        array[i],array[i+1] = array[i+1],array[i]

相关文章

网友评论

      本文标题:Bubble Sort

      本文链接:https://www.haomeiwen.com/subject/jovwhftx.html