Write a function palindrome that takes a vector parameter and returns true
or false according to whether the vector does or does not read the same
forward as backward (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but
a vector containing 1, 2, 3, 4 is not).
[code]
#include <vector>
#include <iostream>
using namespace std;
void palindrome(vector<int>);
int main()
{
int x;
vector<int>values;
while(!x ==".")
{
cout<<"enter your numbers (end with a \".\"):";
cin>>x;
}
Line 17 is a range-based for loop (added in the 2011 revision of the standard). for( int v : values ) reads as: for each intv in the sequence values
See: http://www.stroustrup.com/C++11FAQ.html#for
> its a bit complicated for me to understand the way u did it..
Check if the left half of the sequence is (lexicographically) equal to the right half in reverse.
Sequence: 1 2 3 4 5 4 3 2 1
size: 9, size/2 == 4
From begin() up to, not including begin()+size/2: 1 2 3 4
From rbegin(): starting from the last element (the last 1) in reverse.