Question binarysearch and multidimentional array

andrews

Well-known member
Joined
Nov 22, 2011
Messages
135
Programming Experience
5-10
I have a question about binarysearch and multidimentional array.
Suppose the array
ar(n,3)

ar(1,1) = 50
ar(1,2) = 57
ar(1,3) = 20

ar(2,1) = 278
ar(2,2) = 24
ar(2,3) = 21

....


and suppose that ar is sorted on index 3
for a fast search I want to use binarysearch for that index
is this possible ?
are there methods in vb.net or must i make myself a function for that problem
Thanks for any response
 
Firstly, what does "sorted on index 3" even mean? Do you actually mean sorted on the second dimension? Regardless, just about all inbuilt array functions are for arrays with a single dimension only. That's because there is no one way to work with multi-dimensional arrays. You might consider the first dimension to be the rows and the second to be the columns and someone else might consider it to be the other way around. In short, when working with multi-dimensional arrays, you have to code pretty much everything yourself other than indexing and counting.

Also, while they do have there place. multi-dimensional arrays often get abused. In my experience, the vast majority of cases where people ask questions about using a multi-dimensional array would be better handled by an array with a single dimension or a collection where the elements or items are objects of a custom type with multiple properties.
 
Thanks for your response.
By sorting here I mean that the item with ar(1,..) comes before ar(2,..) because ar(1,3) < ar(2,3) and so on.
I have programmed this sub myself earlier.
I have now a answer to my question because the method in vb.net is not existing like you said by making now a second array aside of the first.
 

Latest posts

Back
Top