ソースを参照

QuickBubblesortwithgood complexity

pull/5/head
Sunny Pate 5年前
コミット
5cfce3ba4c
2個のファイルの変更22行の追加0行の削除
  1. バイナリ
      .DS_Store
  2. +22
    -0
      sorting/QuickBublesort.py

バイナリ
.DS_Store ファイルの表示


+ 22
- 0
sorting/QuickBublesort.py ファイルの表示

@ -0,0 +1,22 @@
# coding: utf-8
# In[45]:
alist = [54,26,93,17,77,31,44,55,20]
def shortBubbleSort(alist):
exchanges = True
passnum = len(alist)-1
while passnum > 0 and exchanges:
exchanges = False
for i in range(passnum):
if alist[i]>alist[i+1]:
exchanges = True
temp = alist[i]
alist[i] = alist[i+1]
alist[i+1] = temp
passnum = passnum-1
return alist
print(shortBubbleSort(alist))

読み込み中…
キャンセル
保存