Answer the question
In order to leave comments, you need to log in
How to check arrays for symmetry about the center in C++?
Hey! Guys, please help me to solve a simple problem: given dynamic arrays of n elements, you need to check whether they are symmetrical about the center?? those. {1, 2, 3} is symmetrical {3, 2, 1}
the problem is that the number of elements can be even, then the problem is unsolvable) but as I understand it, you can get around by setting 2 * n-1 the number of elements
Answer the question
In order to leave comments, you need to log in
Yes, complex labs are now gone, no way without a toaster :) It doesn't
matter how many N ( {1,2,2,1}, for example, is symmetrical )
int i = 0, j = N -1;
while ( i < j )
{
if ( v[i++] != v[j--] )
{
return false;
}
}
return true;
P.S. I sleep already, 2 arrays. Ok, while->for ( int i =0; i < N; ++i ) if( v1[i] != v2[N - i - 1] ) return false; return true;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question