I want Java code that can compare in this way (for example):
<1 2 3 4> = <3 1 2 4>
<1 2 3 4> != <3 4 1 1>
I can\'t
Here is a fix for the code that you posted.
for(int i = 0; i < n; i++)
{
int j;
for(j = 0; j < n; j++)
{
if(a[i] == b[j]) break;
}
if (j == n) return false;
}
return true;
That algorithm is going to break done for arrays that contain duplicates, however. For example, the array {1, 1, 2, 3}
will be found as a match to the array {1, 2, 2, 3}
.
I would highly recommend that you implement a sort-and-compare algorithm instead.