Hello,
In a method i am calculating the longest row of elements. The 1-dim array is filled up with random values (0 or 1).
The method looks up the longest row (being 0 or 1, whatever is the longest).
Meaning in for example:
1110100 --> the longest row would be 3 (3 * 1)
0110000 --> the longest row would be 4 (4 * 0)
The first example has the longest row of 3 elements (3 times 1).
For 1110100 the position in the array would be 0 - 2 (0 - 2 as in the positions on the array)
For 0110000 the position in the array would be 3 - 6 (3 - 6 as in the positions on the array)
I have been trying with foreaches, for loops etc..but i cannot seem to get the proper indexes of both.
Cannot seem to display both positions properly.
For the first example the correct output wouldbe: The largest row of same elements of the array consists of 3 elements on the position 0 -> 2.
The longest row of elements gets of same elements get calculated as the following:
public int BerekenDeelrij (int [] table)
(
int count = 0;
int value = 0;
int largest = 0;
for (int i=0; i < tabel.Length; i++)
(
if (value == tabel[i])
counter + +;
else
(
largest = Math.Max largest (largest, counter);
final value = value
count = 1;
)
)
Math.Max return (largest, counter);
)
Best Regards.