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
I think it would be sensible to check that the lengths of both arrays are equal before doing any iterating. It's a cheap way to opt out of hard work early, and it fixes the following type of failure for the second approach you mention:
{1, 2, 3}
seen as equal to {4, 3, 2, 1}
if you take one array as 1,2,3,4,3,1,2,4 then the solution is in this way.
2n = total number of integers : 8
//program
int i, j, n = 4;
for(i = 0; i < n; i++)
for(j = n; j < 2n; j++)
{
if( a[i] != a[j])
{
j++;
}
else
{
i++; exit();
}
}
if (i == n)
{ //They both are equal;
}
else if(i != n)
{
//They both are not equal;
}
If it is not working please comment on it. Thank You.