29.10.2018, 09:44
Why would you do the checks n * n times?
Further more you should check if they are the same size before iterating through them.
It takes O(n) time at worst case.
Further more you should check if they are the same size before iterating through them.
pawn Код:
new bool:are_same;
// If they are the same size
if (sizeof arr1 == sizeof arr2)
{
// Assume both arrays are the same
are_same = true;
// Iterate through both arrays
for (new i; i < sizeof arr1; i++)
{
// If both elements are not the same
if (arr1[i] != arr2[i])
{
// Both arrays are not the same
are_same = false;
// No need to check further elements
break;
}
}
}
// "are_same" is "true" if both arrays are the same, otherwise "false"
