Skip to content

Instantly share code, notes, and snippets.

Created June 28, 2012 05:36
Show Gist options
  • Save anonymous/3009327 to your computer and use it in GitHub Desktop.
Save anonymous/3009327 to your computer and use it in GitHub Desktop.
#include <stack>
#include <queue>
#include <cstdlib>
#include <string>
using namespace std;
string toLower(string strr)
{
char str[100];
string ret;
strcpy(str,strr.c_str());
int differ = 'A'-'a';
char ch;
int ii = strlen(str);
for (int i=0; i <ii;i++)
{
strncpy(&ch,str+i,1);
if (ch>='A' && ch<='Z')
{
ch = ch-differ;
memcpy(str+i,&ch,1);
}
}
ret = str;
return ret;
}
bool isPalindrome(const std::string& s)
{
s = toLower(s);
stack<char> stack;
queue<char> queue;
int string_index = 0;
for (int i = 0; i < (int) s.length() - 1; i++)
{
queue.push(s[string_index]);
stack.push(s[string_index]);
string_index++;
}
for (int i = 0; i< (int) s.length() - 1; i++)
{
if(queue.size() == 0)
{
return true;
}
if ( queue.pop() != stack.pop())
{
return false;
}
}
return true;
}
void main()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment