1
0
Fork 0
This repository has been archived on 2021-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
uni-m.cds-adv-prog/ex7.2/main.cpp

43 lines
694 B
C++
Raw Normal View History

2020-01-06 15:20:05 +01:00
#include <iostream>
#include <vector>
template<class T>
bool isPalindrome(std::vector<T> v) {
// The Empty Vector is also a Palindrome I guess
if ( v.begin() == v.end() ) {
return 1;
}
auto iter_front = v.begin() ;
auto iter_end = v.end() - 1;
// If
while ( iter_front < iter_end ) {
// Values are not the same so it is not a palindrome
if ( *iter_front != *iter_end ) {
return 0;
}
// Move iterators
iter_front++;
iter_end--;
}
return 1;
}
int main() {
std::vector<int> l = {1, 2, 3, 2, 1};
if ( isPalindrome(l) ) {
std::cout << "This is a Palindrome" << std::endl;
}
else {
std::cout << "This is *not* a Palindrome" << std::endl;
}
return 0;
}