<%@ Page Language="vb" %>
<HTML>
<HEAD>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer = 0
Dim arrayDaOrdinare As Integer() = New Integer() {10, 20, 340, 21, 5, 220, 43, 92, 249, 1000, 12}
'effettuo il bubble sort
DoBubbleSort(arrayDaOrdinare)
'stampo l'array ordinato
For i = 0 To arrayDaOrdinare.GetUpperBound(0)
Response.Write(arrayDaOrdinare(i) & "<br>")
Next
End Sub
Sub DoBubbleSort(ByVal arrayDaOrdinare As Integer())
Dim i, j As Integer
For i = 0 To arrayDaOrdinare.GetUpperBound(0)
For j = 0 To arrayDaOrdinare.GetUpperBound(0) - 1
If arrayDaOrdinare(j) > arrayDaOrdinare(j + 1) Then
scambiaValori(arrayDaOrdinare, j)
End If
Next
Next
End Sub
Sub scambiaValori(ByVal arrayDaOrdinare As Integer(), ByVal primo As Integer)
Dim tmp As Integer = arrayDaOrdinare(primo)
'scambio i valori
arrayDaOrdinare(primo) = arrayDaOrdinare(primo + 1)
arrayDaOrdinare(primo + 1) = tmp
End Sub
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
</form>
</body>
</HTML>