python&groovy冒泡排序

2020-12-13 03:45

阅读:346

标签:lis   bre   name   str   class   nbsp   直接   list   __name__   

无论天空有多高,踮起双脚就能靠近太阳

Groovy:

直接用sort():

class Example {
   static void main(String[] args) {
      def lst = [13, 12, 15, 14];
      def newlst = lst.sort();
      println(newlst);
   }
}

 

Python:

def bubble_sort(alist):
    n = len(alist)
    for i in range(0, n - 1):
        count = 0
        for j in range(0, n-i-1):
            if alist[j] > alist[j + 1]:
                alist[j], alist[j + 1] = alist[j + 1], alist[j]
                count += 1
        if 0 == count:
            break

if __name__ == "__main__":
    alist = [1, 3, 19, 29, 35, 56, 89]
    print(alist)
    bubble_sort(alist)
    print(alist)

python&groovy冒泡排序

标签:lis   bre   name   str   class   nbsp   直接   list   __name__   

原文地址:https://www.cnblogs.com/citicto/p/11087242.html


评论


亲,登录后才可以留言!