I have the following program that creates 100 random elements through an array. These 100 random values are unique, and each value is displayed only once.
Although in a linear search, he continues to search the entire array. How can I get a Jagged Array so that it only "views" the remaining places? (assuming I keep a table of 100 maximum elements, so if one random value is generated, the array contains 99 elements with linear search scanning and ...)
I guess I would have to embed a jagged array somewhere in FoundLinearInArray?
Hope this did it all. Regards.
private int ValidNumber(int[] T, int X, int Range)
{
Random RndInt = new Random();
do
{
X = RndInt.Next(1, Range + 1);
} while (FoundLinearInArray(T, X));
return X;
}
private bool FoundLinearInArray(int[] A, int X)
{
byte I = 0;
while ((I < A.Length) && (A[I] != X))
{
I++;
}
return (I < A.Length);
}
public void FillArray(int[] T, int Range)
{
for (byte I = 0; I < T.Length; I++)
{
T[I] = ValidNumber(T, I, Range);
}
}