0
Pallindrome using vectors
How can I make this code work. I am getting error of no matching function call https://code.sololearn.com/c70U50f9ER3w/?ref=app
9 Réponses
+ 1
You can use reverse_iterator to copy contents of one std::vector to another.
After copying, you can use a loop to compare items from both <A> and <B> (at i-th index) for equality. If any difference were found, return false. If the loop ends with no difference found, return true.
https://code.sololearn.com/cPVKo32X4V71/?ref=app
+ 1
Ipang can you explain the for loop you used to compare the 2 vectors
+ 1
Here, <from> and <to> are variables representing indices, and we use these indices to compare contents of <A> and <B>, at the same index, one by one.
Having contents of <A> copied into <B> in reversed order; we have
0 1 2 3 4 <- index
A {1, 2, 3, 2, 1} <- values
B {1, 2, 3, 2, 1}
So we go checking whether element of <A> at index <from> equals to element of <B> (at the same index).
At any time during the check (in loop iteration), we return false in case we see element of <A> at index <from> being different from element of <B> at index <from>.
But IF the loop finished with no difference noticed, we return true, meaning the vector contains palindromic items.
+ 1
Ipang Superb explanation, thank you Sir🙂
+ 1
Glad if it helps 👌
0
In line 8, it should be template<typename T> bool pallindrome(std::vector<T>&A);
0
Okay I corrected that..but im getting error of undefined reference to bool pallindrome
0
What is the Modern application of C++.