2
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 5 years have passed since last update.

ソートってなんだよ(哲学)

Last updated at Posted at 2019-10-10

スターリンソートアベソートコミューンソートで腹を抱えて笑ったわけだが、ソートという概念要素数や要素そのものに頓着しないというフウチョウを持ち込むなら、以下のアルゴリズム(実際の処理は知らん)が最速になるはずだ。

実装

sort.py
from typing import List, Any


def sort(data):
    # type: (List[Any]) -> None
    data.clear()


def main():
    # type: () -> None
    data = [1, 2, 1, 1, 4, 3, 9,]
    print(F'Before Data: {data}')
    
    sort(data)
    print(F' After Data: {data}')


if __name__ == '__main__':
    main()
λ python sort.py
Before Data: [1, 2, 1, 1, 4, 3, 9]
 After Data: []

見ての通り、昇順に並べ替えられている左様でございますな?

計算量は理論1上 $O(1)$ だと思うけどどうでもいいですね。

命名

スターリンソートのようなセンスのいい名前が思いつかない。

とりあえずドゥームズデイソートとでも名付けておこう。

ぶっちゃけ

多分既出だと思うけどこんなもん既出かどうか調べている暇があったら寝なさい。

睡眠不足はいい仕事の大敵です。

あっ、普通にいるわ

追記

ネタかぶりをして悔しかったので、続きました

  1. Python 内部での実際の処理がどうなっているかは知らないけど、理屈の上では、の意味。 なんなら空リストと取り替えればいい。

2
0
0

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
2
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?