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,844 questions

55,671 answers

573 users

How to check if a given row is sorted in a matrix with VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Private Shared Function isRowSorted(ByVal matrix As Integer(,), ByVal row As Integer) As Boolean
        Dim cols As Integer = matrix.GetLength(1)

        For i As Integer = 1 To cols - 1
            If matrix(row, i - 1) > matrix(row, i) Then
                Return False
            End If
        Next

        Return True
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim matrix As Integer(,) = {
        		{ 1,   2,   3,   4,  0},
        		{-5,  -4,   0,   8,  9},
        		{ 2, 100,   8, 100,  3},
        		{ 1,   7, 100,   9,  6},
        		{ 9,  10,  11,  12, 13}
		}
	
        Console.WriteLine("Row 0: " & isRowSorted(matrix, 0))
        Console.WriteLine("Row 1: " & isRowSorted(matrix, 1))
        Console.WriteLine("Row 2: " & isRowSorted(matrix, 2))
        Console.WriteLine("Row 3: " & isRowSorted(matrix, 3))
        Console.WriteLine("Row 4: " & isRowSorted(matrix, 4))
    End Sub
End Class



' run:
'
' Row 0: False
' Row 1: True
' Row 2: False
' Row 3: False
' Row 4: True
'

 



answered Jun 23, 2023 by avibootz

Related questions

1 answer 151 views
2 answers 209 views
2 answers 215 views
1 answer 158 views
1 answer 178 views
...