Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,940 questions

51,877 answers

573 users

How to reorder an array according to given indexes in VB.NET

1 Answer

0 votes
Imports System
 
Public Class Program
    Public Shared Sub print(ByVal arr As Integer())
        Dim size As Integer = arr.Length
 
        For i As Integer = 0 To size - 1
            Console.Write(arr(i) & " ")
        Next
 
	Console.WriteLine()
    End Sub
 
    Public Shared Sub reorder(ByVal arr As Integer(), ByVal indexes As Integer(), ByVal i As Integer)
        Dim size As Integer = arr.Length
 
        If i < size Then
            Dim data As Integer = arr(i)
            reorder(arr, indexes, i + 1)
            arr(indexes(i)) = data
        End If
    End Sub
 
    Public Shared Sub Main()
        Dim arr As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
        Dim indexes As Integer() = {1, 0, 4, 3, 2, 5, 9, 7, 8, 6}
     
        print(arr)
        print(indexes)
     
        reorder(arr, indexes, 0)
     
        print(arr)
    End Sub
End Class
 
 
 
 
' run:
'
' 1 2 3 4 5 6 7 8 9 10 
' 1 0 4 3 2 5 9 7 8 6 
' 2 1 5 4 3 6 10 8 9 7
'

 



answered Nov 28, 2021 by avibootz
edited Nov 29, 2021 by avibootz

Related questions

1 answer 255 views
1 answer 175 views
1 answer 193 views
1 answer 184 views
1 answer 181 views
1 answer 224 views
1 answer 178 views
...