1
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.

【Unity/C#】ノームソートとは(コード付き)

Last updated at Posted at 2020-07-09

#ノームソートとは
ノームソートはソートアルゴリズムの一種で、挿入ソートに似ているが、要素の移動は挿入ではなくバブルソートのような一連の交換で行う。その名称の由来は、オランダのノームが一列に並んだ鉢植えの花をソートする話である。

#実行結果
ノームソート.gif

#サンプルコード

	void GnomeSort(int[] _array)
	{

		int gnome = 1;

		while (gnome < _array.Length)
		{
			if (_array[gnome] < _array[gnome - 1])
			{

				_array[gnome - 1] ^= _array[gnome];
				_array[gnome] ^= _array[gnome - 1];
				_array[gnome - 1] ^= _array[gnome];

				gnome--;

				
				if (gnome == 0)
				{
					gnome++;
				}
			}
			else
			{

				gnome++;
			}
		}
	}
1
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
1
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?