/*
 * Palindrome.java
 *
 * Author: 
 * Date: 
 */

public class Palindrome {
    public static boolean palindrome(String str) {
        Stack<char> stack = new LLStack<char>();

        // push the first half of the string onto the stack
        for (int i = 0; i < str.length() / 2; i++) {
            stack.push(str.charAt(i));
        }

        // pop the second half from the stack and compare
        for (int i = str.length() / 2; i < str.length(); i++) {
            char c = stack.pop();

            if (c != str.charAt(i)) {
                return false;
            } else {
                return true;
            }
        }

        return true;
    }

    public static void main(String[] args) {
        System.out.println("Is redder a palindrome? Should be true:");
        System.out.println(palindrome("redder"));

        System.out.println("Is reddest a palindrome? Should be false:");
        System.out.println(palindrome("reddest"));

        System.out.println("Is racecar a palindrome? Should be true:");
        System.out.println(palindrome("racecar"));

        System.out.println("Is banana a palindrome? Should be false:");
        System.out.println(palindrome("banana"));

        System.out.println("Is computerscience a palindrome? Should be false:");
        System.out.println(palindrome("computerscience"));

        System.out.println("Is malayalam a palindrome? Should be true:");
        System.out.println(palindrome("malayalam"));
    }
}
