public class PalindromeQueue { private String st = ""; public PalindromeQueue(){} public PalindromeQueue(String str){this.st = str;} public static boolean checkPalindrome(String st){ st = st.trim().toUpperCase(); myQueue mq = new myQueue(st.length()); myQueue mq2 = new myQueue(st.length()); boolean palin = false; if(st.length() < 2) palin = true; else if(st.length()%2 == 0){ for (int j = 0; j < st.length()/2; j++){//Enqueue() the first half of the string into the first queue. mq.enQueue(new Character(st.charAt(j))); } for (int k = (st.length() - 1); k >= st.length()/2; k--){ mq2.enQueue(new Character(st.charAt(k)));//Enqueue() the second half of the string into the 2nd queue. } }else{ for (int j = 0; j < st.length()/2; j++)//Enqueue() the first half of the string into the first queue. mq.enQueue(new Character(st.charAt(j))); for (int k = (st.length() - 1); k > st.length()/2; k--) mq2.enQueue(new Character(st.charAt(k)));//Enqueue() the second half of the string into the 2nd queue. } while(!mq.isEmpty()){ if(mq.deQueue().toString().compareTo(mq2.deQueue().toString()) == 0){ palin = true;//DO NOT BREAK OUT of the loop. We NEED to pop() all elements } else{ palin = false;//from the current stack out to empty the stack. Otherwise comparison will be INCORRECT. break; }//end of if() }//end of WHILE() return palin; } }