最近は話題の無いときのC#ですね。少しずつ変更してきてます。但し、環境は
以前は桜エディターで入力して、コマンドプロンプトからcscを起動してましたが
それよりマイクロソフトのStudio2010が只で使えて、入力もインテリジェントですか
途中まで入力すると、該当する物を表示してくれますので、それでビルドしてます。
それをエディターにコピーしたのが下です。コマンドプロンプトからコンパイルは
OKです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public static void ShellSort<T>(T[] a)
where T : IComparable<T>
{
int n = a.Length;
int h;
for (h = 1; h < n / 9; h = h * 3 + 1) ;
for (; h > 0; h /= 3)
for (int i = h; i < n; i++)
for (int j = i; j >= h && a[j - h].CompareTo(a[j]) > 0; j -= h)
Swap(ref a[j], ref a[j - h]);
}
public static void BubbleSort<T>(T[] a)
where T : IComparable<T>
{
int n = a.Length;
for (int i = 0; i < n - 1; i++)
for (int j = n - 1; j > i; j--)
if (a[j].CompareTo(a[j - 1]) < 0)
Swap(ref a[j], ref a[j - 1]);
}
public static void Swap<T>(ref T a, ref T b)
{
T c = a; a = b; b = c;
}
static void Main(string[] args)
{
Entry[] list = new Entry[]{
new Entry("スズキ", "鈴木"),
new Entry("サトウ", "佐藤"),
new Entry("イトウ", "伊藤"),
new Entry("タカハシ", "高橋"),
new Entry("スガワラ", "菅原"),
new Entry("クマガイ", "熊谷"),
new Entry("チバ", "千葉"),
new Entry("タカナシ", "小鳥遊")};
//Array.Sort(list);
//BubbleSort( list );
bool done = false;
while (!done)
{
ShellSort(list);
for (int i = 0; i < list.Length; ++i)
Console.Write("{0}, {1}, {2}\n", i, list[i].Yomi(), list[i].Namae());
Console.WriteLine("1=訂正\n");
//Console.WriteLine("2=継続\n");
Console.WriteLine("5=終了\n");
int j = int.Parse(Console.ReadLine());
switch (j)
{
case 1:
saido:
done = false;
Console.WriteLine("訂正する番号を入力\n");
int k = int.Parse(Console.ReadLine());
if (!(k > 0 & k <= list.Length))
goto saido;
//Console.WriteLine("読みを入力 半角カタカナ\n");
//string w1 = Console.ReadLine();
//list[k].Yomi(w1);
//Console.WriteLine("氏名を入力 漢字\n");
//string w2 = Console.ReadLine();
//list[k].Namae(w2);
list[k].OneDataInput();
break;
case 5:
done = true;
break;
default:
break;
}
}
//foreach (Entry entry in list)
//{
// Console.Write("{0}, {1}\n", entry.Yomi(), entry.Namae() );
//}
}
}
}
namespace ConsoleApplication1
{
public class Entry : IComparable<Entry>
{
private string yomi;
private string namae;
public Entry(string yomi, string namae)
{
this.yomi = yomi;
this.namae = namae;
}
int IComparable<Entry>.CompareTo(Entry other)
{
return this.yomi.CompareTo(other.yomi);
}
public void Yomi(string value) { this.yomi = value; }
public string Yomi() { return this.yomi; }
public void Namae(string value) { this.namae = value; }
public string Namae() { return this.namae; }
public void OneDataInput()
{
Console.WriteLine("読み方 カタカナハンカク:");
yomi = Console.ReadLine();
Console.WriteLine("漢字氏名:");
namae = Console.ReadLine();
}
}
}
※コメント投稿者のブログIDはブログ作成者のみに通知されます