In the code above the else-if part gives me error. The meaning of else-if is: else if the value of x isn’t in the deque then…
#include <iostream>
#include <ctime>
#include <stack>
#include <deque>
#include <algorithm>
deque<char> visited;
char x;
if (x==target[4][4])
{
visited.push_back(x);
return (visited);
}
else if (!(find(visited.begin(), visited.end(), x)))
{
visited.push_back(x);
}
ERROR:no operator “!” matches these operands
If
std::findcannot find the specific value, it will return the “end” of the iterator pair.Edit: If you want to know if x is in the deque, just reverse the condition.
Edit: If you are unfamiliar with the iterator concept in C++, please read Understanding Iterators in the STL.