とりこらぼ。

Learn from yesterday,
live for today,
hope for tomorrow.

目次

Blog 利用状況

ニュース

プロフィール

  • 名前:とりこびと
    とるに足らない人間です。

  • Wankuma MVP
    for '平々凡々'

Web Site

  • Memo(Of T)

もうひとつの Blog

広告っぽい

書庫

日記カテゴリ

ソートされたらいいな、をカタチにする。

のんちゃんのVBお勉強に協力する試み (1)

とりこびとなりの応援です。


でも、あったらいいな、はカタチにできません!!(キッパリ

ソートされてるかどうかを調べるくらいならできそうです。(コラw

Option Compare Binary
Option Explicit On
Option Infer On
Option Strict On
Imports System Imports System.Collections.Generic
Namespace Wankuma.Festivals.SortFestival.Torikobito     Module Program
        Sub Main()
            Dim seeds = GetSeeds(50100000)
            Console.WriteLine("--  Before --")
            For i = 0 To seeds.Count - 1
                Console.WriteLine(seeds.Item(i).ToString)
            Next
            Sort(seeds)
            Console.WriteLine("--  After --")
            For j = 0 To seeds.Count - 1
                Console.WriteLine(seeds.Item(j).ToString)
            Next         End Sub
        Private Function GetSeeds(ByVal count As IntegerByVal minValue As IntegerByVal maxValue As IntegerAs List(Of Integer)
            Dim list = New List(Of Integer)(count)
            Dim r = New Random()
            For i = 0 To count - 1
                ' あ、maxValue は排他的上限値なのね…。                 Dim seed = r.Next(minValue, maxValue)                 list.Add(seed)
            Next
            Return list
        End Function
        Private Sub Sort(ByVal list As List(Of Integer))
            Dim sorted = False
            While Not sorted
                Shuffle(list)
               ' どうかソートされていますように・・・。
                sorted = True
                For i = 0 To list.Count - 2
                    If list.Item(i) > list.Item(i + 1Then
                        ' ダメでしたか…。                         sorted = False                         Exit For
                    End If
                Next
            End While
        End Sub
        Private Sub Shuffle(ByVal list As List(Of Integer))
            Dim r = New Random()
            For i = 0 To list.Count - 1
                Dim value = r.Next(list.Count)                 Dim temp = list.Item(i)                 list.Item(i) = list.Item(value)                 list.Item(value) = temp
            Next
        End Sub
    End Module
End Namespace

投稿日時 : 2008年7月19日 10:06

Feedback

# 【20080920東京勉強会#24】準備エントリ 2008/08/12 16:10 はつね

【20080920東京勉強会#24】準備エントリ

# kBgUklKAqFx 2012/01/07 3:35 http://www.luckyvitamin.com/c-1471-co-enzyme-q-10

It's pleasant sitting at work to distract from it?to relax and read the information written here:D

# Wheoevr wrote this, you know how to make a good article. 2013/01/16 11:40 Ziarre

Wheoevr wrote this, you know how to make a good article.

タイトル  
名前  
Url
コメント