Created
September 27, 2016 23:28
-
-
Save bakkiraju/73cbe766827d5bf83d76942117347f9a to your computer and use it in GitHub Desktop.
palindrom check using std::deque
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <deque> | |
| using namespace std; | |
| bool isPalindrome(const char *in) { | |
| deque<char> dq; | |
| while (*in != '\0') { | |
| dq.push_back(*in); | |
| in++; | |
| } | |
| while (!dq.empty()) { | |
| if (dq.size() == 1) | |
| return true; | |
| if (dq.front() != dq.back()) | |
| return false; | |
| dq.pop_back(); dq.pop_front(); | |
| } | |
| return true; | |
| } | |
| int main() { | |
| string s = "t"; | |
| cout << isPalindrome(s.c_str()); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment