何か、επιστημηさんのところで(というかわんくま同盟内で?)ソート祭りだそうなので、せっかくなので挑戦してみる。
Option Explicit On
Imports System.Diagnostics
Imports System.Collections.Generic
Module Program
Sub Sort(elm() As Integer)
Dim startInfo As New ProcessStartInfo("sort")
startInfo.CreateNoWindow = True
startInfo.RedirectStandardError = False
startInfo.RedirectStandardInput = True
startInfo.RedirectStandardOutput = True
startInfo.UseShellExecute = False
Dim maxLen As Integer
maxLen = 0
For Each e As Integer In elm
Dim len As Integer
len = e.ToString().Length
If len > maxLen Then
maxLen = len
End If
Next
Dim proc As New Process
proc.StartInfo = startInfo
If proc.Start Then
For Each e As Integer In elm
proc.StandardInput.WriteLine("{0:D" & maxLen.ToString() & "}", e)
Next
proc.StandardInput.Close
Dim result As New List(Of Integer)
While Not proc.StandardOutput.EndOfStream
Dim line As String
line = proc.StandardOutput.ReadLine
line.TrimEnd(Nothing)
result.Add(Integer.Parse(line))
End While
result.ToArray().CopyTo(elm, 0)
proc.Close
End If
End Sub
Sub Main()
Dim elm() As Integer = { 3, 1, 4, 1, 4, 9, 10, 99, 123 }
For Each e As Integer In elm
Console.WriteLine(e)
Next
Sort(elm)
Console.WriteLine("sorted")
For Each e As Integer In elm
Console.WriteLine(e)
Next
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
End Sub
End Module
よく確認してないので、ネタがかぶってるかも。まぁいいや。
元ネタ(あえてリンク貼らず)の方には「回答公開禁止」とか書いてあるけどwankuma内じゃないし、ネタだしいいよね。つか、ソートの実装とかそこらじゅうに転がってるだろうし。まずかったらきっとTB蹴ってくれることでしょう(まる)
14:00 追記。 elm() に { 1,2,10 } とか入れると 1 10 2 の順に表示しやがるので、ちょっとコード修正。そういやsortは文字列としてソートするんだった。





コメントする