「選択ソート」の版間の差分

削除された内容 追加された内容
Cewbot (会話 | 投稿記録)
m Bot作業依頼: sourceタグをsyntaxhighlightタグに置換 (Category:非推奨のsourceタグを使用しているページ) - log
syntaxhighlight タグの 言語を指定 / C#コード修正(不要なusingを除去)
28行目:
 
===Pythonでの実装例===
<syntaxhighlight lang = "textpython">
#非破壊操作
def selectionSort(list):
62行目:
 
===C#での実装例===
<syntaxhighlight lang = "textcsharp">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace SelectionSort
79 ⟶ 75行目:
Console.Write("ソートしたいデータ数を入力ください : ");
int dataNumber = Convert.ToInt32(Console.ReadLine());
int[] Arrayarray = new int[dataNumber];
Console.WriteLine("\n");
 
85 ⟶ 81行目:
{
Console.Write("[" + (i + 1) + "]番目のデータを入力してください : ");
Arrayarray[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("\n");
foreach (int a in Arrayarray)
Console.Write(a + " ");
 
for(int i = 0; i < Arrayarray.Length; i++)
{
for(int j = i + 1; j < array.Length; j++)
for(int j = i + 1; j < Array.Length; j++)
{
if(Arrayarray[j] < Arrayarray[i])
{
temp = Arrayarray[i];
Arrayarray[i] = Arrayarray[j];
Arrayarray[j] = temp;
}
}
106 ⟶ 101行目:
Console.WriteLine("\n");
Console.WriteLine("ソートされた結果 : ");
foreach (int n in Arrayarray)
Console.Write(n + " ");
Console.ReadKey();