Skip to content

Instantly share code, notes, and snippets.

@bakkiraju
Created September 27, 2016 23:28
Show Gist options
  • Select an option

  • Save bakkiraju/73cbe766827d5bf83d76942117347f9a to your computer and use it in GitHub Desktop.

Select an option

Save bakkiraju/73cbe766827d5bf83d76942117347f9a to your computer and use it in GitHub Desktop.
palindrom check using std::deque
#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