简体   繁体   中英

compare 2D array with 1D array

how I can compare each row of 2D array with 1d array in order to insert 1D array if it is not found in 2D array if my 2d array is like {{3,7,9},{1y ,8,6}} and my 1d array for example {3,7,9},how I can know if it's already there ,my code below insert 1d array at a time to 2d array ,I tried to use .equal but it doesn't work

    Private Sub Add_Item_Array_2D2(ByRef Array_2D As Double(,), ByVal d As Integer,
                        ByVal Items As Double())
    Dim tmp_array(Array_2D.GetUpperBound(0) + d, Array_2D.GetUpperBound(d)) As Double

    For n As Integer = 0 To Array_2D.GetUpperBound(0)
        For m = 0 To Array_2D.GetUpperBound(1)
            Dim pp = (Array_2D(n, m)).Equals(Items)
            If pp = False Then

                For x As Integer = 0 To Array_2D.GetUpperBound(0)
                    For k = 0 To Array_2D.GetUpperBound(1)

                        tmp_array(x, k) = Array_2D(x, k)
                    Next
                Next
                For j = 0 To Items.Count - 1


                    tmp_array(tmp_array.GetUpperBound(0), j) = Items(j)

                Next
                Array_2D = tmp_array


            End If

        Next
    Next

End Sub

How to find out whether a row in your 2D array equals your 1D array:

Compare bounds. If the column count of your 2D array is unequal 
to the length of your 1D array, throw an error.

Loop through the rows of the 2D array:
    If, for all column indexes, 2D(row, column) = 1D(column):
        return Success

return Failure

Translating this algorithm to VB.NET is left as an exercise. Hint: For the for all part, Enumerable.Range and Enumerable.All might be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM