Python: 冒泡排序

来源:互联网 发布:大数据 消费者洞察 编辑:程序博客网 时间:2024/05/19 22:45

Python: 冒泡排序

标签: python 冒泡排序

by 小威威


刚刚用python写了个冒泡排序,果然比C语言简洁多了。

#!/usr/bin/python3# Filename: Bubblesort2.py# split can turn the string into list#!/usr/bin/python3# Filename: Bubblesort2.py# split can turn the string into listlist = input().split()list = [int(i) for i in list]for i in range(0, len(list)-1):    for j in range(0, len(list)-1-i):        if list[j] > list[j+1]:            temp = list[j]            list[j] = list[j+1]            list[j+1] = tempprint (list)

以上内容皆为本人观点,欢迎大家提出批评和指导,我们一起探讨。


0 0