Home > Software engineering > How to calculate a 2 d array of different element number, and in a one-dimensional array. Thank you!
How to calculate a 2 d array of different element number, and in a one-dimensional array. Thank you!
Time:10-04
How to calculate a 2 d array of different element number, and put in a one-dimensional array, thank you! As follows, it is my train of thought, but the number of elements behind the element number is easy to be covered, For I=0 to X For j=0 to Y For ni=I to X For nj=j to Y If A (I, j)=A (ni, nj) then join A one-dimensional array Next ni Next nj Next I Next j
CodePudding user response:
Using a ListBox, can be set to invisible,
Private Declare Function SendMessagebyString Lib "user32" Alias "SendMessageA" (ByVal hWND As Long, _ ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long As String)
Private Const LB_FINDSTRINGEXACT=& amp; H1A2 'precise search in the ListBox
List1. Clear For I=0 To X For j=0 To Y N=SendMessagebyString (List1. HWnd LB_FINDSTRINGEXACT, 1, A (I, j)) If n=1 then List1. AddItem A (I, j) List1. ItemData (List1. NewIndex)=1 The Else List1. ItemData (n)=List1. ItemData (n) + 1 End the If Next j Next I
Redim number (List1. ListCount - 1) For I=0 To List1. ListCount - 1 Number (I)=List1. ItemData (I) The Debug. Print List1. List (I), List1. ItemData (I) Next I
I wonder if you get a one-dimensional array of intention, then how to know which one of the elements of how many?
CodePudding user response:
Element number is easy to be behind the number of elements override Dizzy, you should use an array instead of a variable to hold a count
CodePudding user response:
You look like this, it is estimated that the number of elements are 1, because when you first get this element, the total number is right, when you check again the second time this element, total have a less, but the number of the original cover, you need to use a temporary array, the original array is passed to the temporary array, temporary array, check check an element of time, will get equal elements are removed, such as change with zero or negative, in a word, just for you can't have some things in the array, so, when you check, add a statement, the if timparry (x)=0 (or change you for something) then exit the for, is the item when you want to, don't look up, so, you should not wrong, the code you write,