1,137 バイト追加
、 2020年2月15日 (土) 07:29
==挿入ソート==
[VC++.NET]{{category ロジック}}
VC++.NET 2005
using namespace System;
using namespace System::Collections;
static void insertionSort( array<String^>^ ary) {
String^ key;
for (long i=1; i < ary->Length; i++) {
for (long j=0; j<i; j++) {
if ( ary[i]->CompareTo(ary[j]) < 0 ) {
key = ary[i];
for (long k=i; k>j; k--) {
ary[k] = ary[k-1];
}
ary[j] = key;
break;
}
}
}
}
static void sort( array<String^>^ ary ) {
insertionSort(ary);
}
static void print( array<String^>^ ary ) {
for (int i=0; i<ary->Length; i++) {
Console::WriteLine(ary[i]);
}
}
int main(array<System::String ^> ^args)
{
String^ line;
IList^ list = gcnew ArrayList();
while ( (line = Console::ReadLine()) != nullptr ) {
list->Add(line);
}
array<String^>^ ary = gcnew array<String^>(list->Count);
list->CopyTo(ary, 0);
sort(ary);
print(ary);
return 0;
}