0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pythonでバブルソート

Posted at

・実行環境

名前 バージョン
Python 3.7.1

ソースコードは以下になります。

src = [3, 5, 1, 8, 5, 9]
print(src)

for i in range(len(src)-1):
    for j in range(len(src)-1-i):
        if src[j] > src[j+1]:
            tmp = src[j]
            src[j] = src[j+1]
            src[j+1] = tmp

print(src)

実行結果は以下のようになります。

[3, 5, 1, 8, 5, 9]
[1, 3, 5, 5, 8, 9]

最後まで読んでいただきありがとうございました。
またお会いしましょう。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?