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

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,690 questions

55,449 answers

573 users

How to print inversions pairs in array in VB.NET

1 Answer

0 votes
' Inversion for an array indicates how far (or close) the array is from being sorted. 
' If the array is sorted then the Inversion is 0.
	
Imports System

Public Class Program
	Public Shared Sub printInversionPair(ByVal arr As Integer())
        Dim size As Integer = arr.Length

        If size <= 1 Then
            Return
        End If

		Dim sorted As Boolean = True

        For i As Integer = 0 To size - 1
            For j As Integer = i + 1 To size - 1
                If arr(i) > arr(j) Then
					sorted = False
                    Console.WriteLine(arr(i) & ", " & arr(j))
                End If
            Next
        Next

        If sorted Then Console.WriteLine("sorted")
    End Sub

    Public Shared Sub Main()
        Dim arr1 As Integer() = {1, 7, 2, 5, 4, 3, 9, 8}
        printInversionPair(arr1)
	
        Dim arr2 As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9}
        printInversionPair(arr2)
    End Sub
End Class



' run:
'
' 7, 2
' 7, 5
' 7, 4
' 7, 3
' 5, 4
' 5, 3
' 4, 3
' 9, 8
' sorted
' 

 



answered Nov 10, 2021 by avibootz
edited Nov 10, 2021 by avibootz

Related questions

1 answer 188 views
1 answer 201 views
201 views asked Nov 10, 2021 by avibootz
1 answer 235 views
1 answer 133 views
133 views asked Nov 10, 2021 by avibootz
1 answer 146 views
1 answer 139 views
1 answer 249 views
...