Imports System
Imports System.Collections.Generic
Public Class Program
Public Shared Sub RearrangeArrayMaxMinForm(ByVal array As Integer())
Dim size As Integer = array.Length
Dim lst As List(Of Integer) = New List(Of Integer)()
Dim left As Integer = 0
Dim right As Integer = size - 1
Dim odd_index As Boolean = True
For i As Integer = 0 To size - 1
If odd_index Then
lst.Add(array(Math.Max(System.Threading.Interlocked.Decrement(right), right + 1)))
Else
lst.Add(array(Math.Min(System.Threading.Interlocked.Increment(left), left - 1)))
End If
odd_index = Not odd_index
Next
For i As Integer = 0 To size - 1
array(i) = lst(i)
Next
End Sub
Private Shared Sub PrintArray(ByVal array As Integer())
For i As Integer = 0 To array.Length - 1
Console.Write(array(i) & " ")
Next
End Sub
Public Shared Sub Main(ByVal args As String())
Dim array As Integer() = New Integer() {1, 2, 3, 4, 5, 6, 7, 8, 9}
RearrangeArrayMaxMinForm(array)
PrintArray(array)
End Sub
End Class
' run:
'
' 9 1 8 2 7 3 6 4 5
'