Linear Search with Jagged Array?
- by Nerathas
Hello,
I have the following program that creates 100 random elements trough a array.
Those 100 random value's are unique, and every value only gets displayed once.
Although with the linear search it keeps looking up the entire array.
How would i be able to get a Jagged Array into this, so it only "scans" the remaining places left? (assuming i keep the table at 100 max elements, so if one random value is generated the array holds 99 elements with linear search scans and on...)
I assume i would have to implent the jagged array somewhere in the FoundLinearInArray?
Hopefully this made any sence.
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;
}/*ValidNumber*/
private bool FoundLinearInArray(int[] A, int X)
{
byte I = 0;
while ((I < A.Length) && (A[I] != X))
{
I++;
}
return (I < A.Length);
}/*FoundInArray*/
public void FillArray(int[] T, int Range)
{
for (byte I = 0; I < T.Length; I++)
{
T[I] = ValidNumber(T, I, Range);
}
}/*FillArray*/