Imports System
Public Class Program
Public Shared Sub swap(ByVal arr As Integer(), ByVal i As Integer, ByVal j As Integer)
Dim temp As Integer = arr(i)
arr(i) = arr(j)
arr(j) = temp
End Sub
Public Shared Sub rearrangeArray(ByVal arr As Integer())
Dim size As Integer = arr.Length
For i As Integer = 0 To size - 1 - 1 Step 2
If arr(i) > arr(i + 1) Then
swap(arr, i, i + 1)
End If
Next
If (size And 1) <> 0 Then
For i As Integer = size - 1 To 0 + 1 Step 2
If arr(i) > arr(i - 1) Then
swap(arr, i, i - 1)
End If
Next
End If
End Sub
Public Shared Sub Main(ByVal args As String())
Dim arr As Integer() = New Integer() {1, 3, 6, 5, 4, 2, 9, 8, 7}
rearrangeArray(arr)
Console.WriteLine(String.Join(" ", arr))
End Sub
End Class
' run:
'
' 1 3 5 6 2 4 8 9 7
'