Reputation: 2902
I have an assignment which says I have to read from file the distances between 20 citys each. I wonder how to handle that data in the application. I thought of multidimensional array, something like Distances(0, 1, 0)=500
which means that the distance between city0 and city1 is 500 miles. Also I think this is a waste of memory because Distances(0, 1, 0)
and Distances(1, 0, 0)
is the same thing. My mentor told me to use triangular matrix to save the data into the app. Can you show me an example of a similar data handling or some other idea of how to handle the data? I just can't imagine it. Thank you!
Upvotes: 0
Views: 260
Reputation: 1398
You want an array of arrays. A multidimensional array is useful if you have a consistent array size for each of the inner arrays, but you want your first array to have length=0, the second to have length=1, etc... So, actually, you don't even need the first array - as it is just empty.
Dim triangle As Array(19)
For i = 0 To 18
Dim innerArray(i+1) As Integer
triangle(i) = innerArray
Next
Upvotes: 0
Reputation: 19564
What I think he means is something like this: http://www.arenalogisticsinc.com/images/chart4.jpg
Basically a 2-D array - And if you want to save space, just remove the top half of the array since it will have repetitions.
Hope this helps.
Upvotes: 1