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?

単純挿入法(挿入ソート)

Last updated at Posted at 2024-05-27

単純挿入法(挿入ソート)とは

データを並べる整列アルゴリズムの一つ。
要素を一つずつ順番に、正しい位置に挿入していくことで、最終的に全体を昇順または降順に並べ替える。

対象データ

以下の配列を昇順に並べ替える

$array = [5, 3, 4, 1, 2];

フローチャート

挿入するデータをxに代入。
xに代入され、空いた要素の添字をkに代入。

image.png

手順

①挿入したいデータは別に変数を用意して代入しておく
②変数のデータを、整列済みデータと順番に比較していく
③変数のデータより小さいデータが見つかったら、その後ろの要素に変数のデータを代入する

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