Does anyone know how to compare the first and second halves of a vector? I'm trying to write a function that returns true if the second half of a vector is identical to the first half of the vector. For example, if the vector contains { 3, 5, 2, 3, 5, 2 }, the function would return true, since the first half consists of 3, 5, 2, and the second half consists of 3, 5, 2. If the vector contains { 3, 5, 2, 3, 2, 5 }, the functions returns false since the sequence 3, 5, 2 is not identical to 3, 2, 5.
If a vector contains an odd number of elements, the middle element does not affect the outcome; so { 2, 1, 2 } is OK, but { 2, 1, 1 } is not. The empty vector is accepted by default, and a vector containing only one element is acceptable.

bool halves_match(const vector<int>& v)
{
    //If Halves Match
    return false;  
}

At least make an attempt to flesh out the function, and someone will be able to help you.

This is not overly difficult but as jonsca said have a go first.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.