前回 に引き続き、もういっちょソートネタ
Option Explicit On
Imports System.Data
Imports System.Data.SQLite
Module Program
Sub Sort(elm() As Integer)
Dim builder As New SQLiteConnectionStringBuilder
builder.DataSource = ":memory:"
Dim conn As New SQLiteConnection
conn.ConnectionString = builder.ConnectionString
conn.Open()
Using conn
Using comm1 As New SQLiteCommand("CREATE TABLE TMP (N NUMBER)", conn)
comm1.ExecuteNonQuery
End Using
Using comm2 As New SQLiteCommand("INSERT INTO TMP (N) VALUES (?)", conn)
For Each e As Integer In elm
Dim param2 As New SQLiteParameter("N", e)
comm2.Parameters.Clear
comm2.Parameters.Add(param2)
comm2.ExecuteNonQuery
Next
End Using
Using comm3 As New SQLiteCommand("SELECT N FROM TMP ORDER BY N", conn)
Dim idx As Integer = 0
Using er As SQLiteDataReader = comm3.ExecuteReader()
While er.Read()
elm(idx) = er.GetInt32(0)
idx = idx + 1
End While
End Using
End Using
End Using
End Sub
Sub Main()
Dim elm() As Integer = { 3, 1, 4, 1, 4, 9, 10, 99, 123, -4 }
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
Sortサブルーチンを挿げ替えてみました。





コメントする