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,

CodePudding user response:

refer to the original poster u012075179 response:
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

I am not a programmer, don't write programs, but intuition in the second paragraph of the logic of thinking you have any question,
"For ni=I to X
For nj=j to Y
"The X, and Y; Should not be with the first paragraph
For ni=I to X
For nj=j to Y
Inside of X and Y value, and use the same coordinate range, if you write this paragraph,
So, in fact, I to ni=?? , I have to the Max value;" Nj=j to?? "J values in it have also been to the Max value,

That behind you two:
Next ni
Next nj
Next I
Next j

Is actually will be covered, and there is no way to loop,
Suppose I=0 to 100; J=0 to 100; Then you ni and nj in fact is equal to 0 to 100,
So your second cycle is actually equal to the first round of the cycle, no matter how you set A (I, j)=A (ni, nj), the final results are only the next and the next I j,

Won't be programming, a shot in the dark, look at your code on your own, feel there is a problem,

CodePudding user response:

The
reference 4 floor frauzhou reply:
Quote: refer to the original poster u012075179 response:

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

I am not a programmer, don't write programs, but intuition in the second paragraph of the logic of thinking you have any question,
"For ni=I to X
For nj=j to Y
"The X, and Y; Should not be with the first paragraph
For ni=I to X
For nj=j to Y
Inside of X and Y value, and use the same coordinate range, if you write this paragraph,
So, in fact, I to ni=?? , I have to the Max value;" Nj=j to?? "J values in it have also been to the Max value,

That behind you two:
Next ni
Next nj
Next I
Next j

Is actually will be covered, and there is no way to loop,
Suppose I=0 to 100; J=0 to 100; Then you ni and nj in fact is equal to 0 to 100,
So your second cycle is actually equal to the first round of the cycle, no matter how you set A (I, j)=A (ni, nj), the final results are only the next and the next I j,

Won't be programming, a shot in the dark, look at your code on your own, have a perception problem,

This period of wrong, I also have a question, attached to a few days in the system, looking for the upgrade, a little tired, the new thought for a moment, you of the outer loop and the inner loop, there is no place,

If the outer loop,
For X=0 to X '
For Y=0 to Y '
Next X
Next Y
Stack a range, end,
So, you is equal to the peripheral definition of in advance the scope, the end of the inner loop, automatic return cycle, but you don't have a separate, equal to do the cycle has been continuously, equivalent to the English called BOX
For nX=X to X '
For nY=Y to Y '
Next nX
Next nY
Actually did not have any effect, equal to did not exist, if circulate in to set up, you have to add another layer of English is called a box, two separate,
Equivalent to computing, there are different range boundaries, outside the first BOX in the X, Y is to define the scope of two-way coordinate value, in the second BOX, nX digital mobile and nY is the actual coordinates calculation value, when the mobile is worth more than defined coordinate values of range, there is no way to calculate the computer, or disappear, or return to the origin of coordinates, namely X=0, Y=0, so, nX and nY, this time also is equal to 0. Because the computer system calculation is based on the hypothesis of dimension, namely physical assumption, if more than the dimension range, then calculate all failed,

CodePudding user response:

Feel the two-dimensional arrays are purely messed up here. The final output is just one dimension array.

First to understand the original poster intentions: seems to be a duplicate of the original data into a one dimensional array to??????? Is
?
If this is the case:
1: apply for a (X + 1) * (Y + 1) the size of the array, pretend is A1 (Z), Z=(X + 1) * (Y + 1) - 1

2: COPYMEMORY, A copy of the two-dimensional array into A one-dimensional array A1

3: a one-dimensional array for repeat does not repeat, the code will be much easier.
  • Related