I've done this in java, but the way of solving the problem is the same
first, each character of the String onto a stack
then pop each character off and compare each character to each character in String
This is what I did in Java:
public boolean palindrome(String string)
{
MyStack myStack = new MyStack();
String split[] = string.split(" "); // split the string by spaces
for (int i = 0; i < split.length; i++)
{
myStack.push(new StackNode(split[i])); // add each character to stack
}
for (int j = 0; j < split.length; j++)
{
String compare = myStack.pop().getData();
if (!compare.equals(split[i]))
return false;
}
if (myStack.pop() != null)
return false;
return true;
}