Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class named Palindrome.java and Write a method isPalindrome that takes a

ID: 3726188 • Letter: W

Question

 Write a class named Palindrome.java and Write a method isPalindrome that takes an IntQueue as a parameter and that returns whether or not the numbers in the queue represent a palindrome (true if they do, false otherwise). A sequence of numbers is considered a palindrome if it is the same in reverse order. For example, suppose a Queue called q stores this sequence of values:          front [3, 8, 17, 9, 17, 8, 3] back Then the following call:          isPalindrome(q) should return true because this sequence is the same in reverse order. If the list had instead stored these values:          front [3, 8, 17, 9, 4, 17, 8, 3] back the call on isPalindrome would instead return false because this sequence is not the same in reverse order (the 9 and 4 in the middle don't match).  The empty queue should be considered a palindrome. You may not make any assumptions about how many elements are in the queue and your method must restore the queue so that it stores the same sequence of values after the call as it did before.  The method header is specified as follows:        public static boolean isPalindrome(IntQueue q) 

Explanation / Answer

Hi friend, you have not posted structure of IntQueue class, so I can not know what are the methods inside this class.

I have implemented after some assumption.

public static boolean isPalindrome(IntQueue q) {

int i = q.getFront();

int j = q.getBack();

while(i < j) {

if(q.get(i) != q.get(j))

return false;

i++;

j--;

}

return true;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote