-
-
Save jhgaylor/3009332 to your computer and use it in GitHub Desktop.
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 <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) | |
{ | |
string new_s = toLower(s); | |
stack<char> stack; | |
queue<char> queue; | |
int string_index = 0; | |
for (int i = 0; i < (int) new_s.length() - 1; i++) | |
{ | |
queue.push(new_s[string_index]); | |
stack.push(new_s[string_index]); | |
string_index++; | |
} | |
for (int i = 0; i< (int) new_s.length() - 1; i++) | |
{ | |
if(queue.size() == 0) | |
{ | |
return true; | |
} | |
if ( queue.top() != stack.top()) | |
{ | |
return false; | |
} | |
stack.pop() | |
queue.pop() | |
} | |
return true; | |
} | |
void main() | |
{ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment