Pallindrome using vectors | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

11th Nov 2021, 10:41 PM
Reynolds Onyango
Reynolds Onyango - avatar
8 Answers
+ 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
12th Nov 2021, 3:04 AM
Ipang
+ 1
Ipang can you explain the for loop you used to compare the 2 vectors
12th Nov 2021, 7:26 AM
Reynolds Onyango
Reynolds Onyango - avatar
+ 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.
12th Nov 2021, 11:00 AM
Ipang
+ 1
Ipang Superb explanation, thank you Sir🙂
12th Nov 2021, 2:16 PM
Reynolds Onyango
Reynolds Onyango - avatar
+ 1
Glad if it helps 👌
12th Nov 2021, 2:22 PM
Ipang
0
In line 8, it should be template<typename T> bool pallindrome(std::vector<T>&A);
11th Nov 2021, 11:08 PM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Okay I corrected that..but im getting error of undefined reference to bool pallindrome
11th Nov 2021, 11:16 PM
Reynolds Onyango
Reynolds Onyango - avatar
0
What is the Modern application of C++.
13th Nov 2021, 1:49 AM
olorunfemi Joshua
olorunfemi Joshua - avatar