Welcome to collectivesolver - Programming & Software Q&A with code examples. A website you can trust. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Dental Dog Chews
FRESH BREATHIES

GlucoTrust is a brand new, science-backed supplement that supports healthy blood sugar levels AND weight loss for men and women

Everything you need to sell anywhere

Managed VPS Hosting
Affordable. Secure. Your Own Virtual Private Hosting. Faster than AWS and Rackspace

Bonsai Boy of New York Bonsai Trees and Accessories
100%

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

25,584 questions

33,347 answers

573 users

How to find all common elements in given three sorted arrays with VB.NET

1 Answer

0 votes
Imports System

Public Class Program
	Public Shared Sub PrintCommonElementsInThreeArrays(ByVal arr1 As Integer(), ByVal arr2 As Integer(), ByVal arr3 As Integer())
        Dim size1 As Integer = arr1.Length
        Dim size2 As Integer = arr2.Length
        Dim size3 As Integer = arr3.Length

        Dim i As Integer = 0, j As Integer = 0, k As Integer = 0

        While i < size1 AndAlso j < size2 AndAlso k < size3
            If arr1(i) = arr2(j) AndAlso arr3(k) = arr1(i) Then
                Console.Write(arr1(i) & " ")
                i += 1
                j += 1
                k += 1
            ElseIf arr1(i) < arr2(j) Then
                i += 1
            ElseIf arr2(j) < arr3(k) Then
                j += 1
            Else
                k += 1
            End If
        End While
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim arr1 As Integer() = New Integer() {2, 5, 6, 7, 9, 12, 20, 25, 30, 31}
        Dim arr2 As Integer() = New Integer() {4, 7, 10, 11, 20, 21, 30, 31, 37}
        Dim arr3 As Integer() = New Integer() {1, 2, 5, 7, 9, 18, 19, 20, 31, 32, 38, 39, 40, 50}
		
        PrintCommonElementsInThreeArrays(arr1, arr2, arr3)
    End Sub
End Class





' run:
' 
' 7 20 31
'

 




answered 5 days ago by avibootz
...