Kirjautuminen

Haku

Tehtävät

Keskustelu: Ohjelmointikysymykset: VB.NET: numeroiden lajittelu

t800 [12.12.2003 18:01:17]

#

miten vb.net saa esim 4 satunnaista lukua laitettua
ns suuruusjärjestykseen?

tnb [12.12.2003 22:01:41]

#

Tässä esimerkki:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mylista() As Single = {7.0, 5.4, 5.4, 0.9}
        Dim s As Single
        TextBox1.Multiline = True
        TextBox1.Height = 100
        kuplasort_nouseva(mylista)
        TextBox1.Text = ""
        For Each s In mylista
            TextBox1.Text = TextBox1.Text & CStr(s) & Chr(13) & Chr(10)
        Next
    End Sub
    Sub kuplasort_laskeva(ByRef lista() As Single)
        Dim i As Integer
        Dim j As Integer
        Dim r As Integer
        Dim temp As Single
        r = UBound(lista)
        For i = 0 To r
            For j = i To r
                If lista(i) < lista(j) Then
                    temp = lista(i)
                    lista(i) = lista(j)
                    lista(j) = temp
                End If
            Next
        Next
    End Sub
    Sub kuplasort_nouseva(ByRef lista() As Single)
        Dim i As Integer
        Dim j As Integer
        Dim r As Integer
        Dim temp As Single
        r = UBound(lista)
        For i = 0 To r
            For j = i To r
                If lista(i) > lista(j) Then
                    temp = lista(i)
                    lista(i) = lista(j)
                    lista(j) = temp
                End If
            Next
        Next
    End Sub

Vastaus

Aihe on jo aika vanha, joten et voi enää vastata siihen.

Tietoa sivustosta