package homework4; public class Homework4 { public static void arrange(int [] arr) { // rearrange arr so that evens occur before odds recArrange(arr, 0, arr.length-1); } private static void recArrange(int [] arr, int left, int right) { // rearrange the portion of arr between left and right if (right <= left ) return; //base case if ( (arr[left] % 2) == 0) { //arr[left] is even recArrange(); //fill in the arguments for recursive call return; } int temp = left; while((temp <= right) && ((arr[temp]%2) != 0)) temp++; // find first even number if (temp > right) { //no even number found return; } // now swap arr[temp] and arr[left] int leftStore = arr[left]; arr[left] = arr[temp]; arr[temp] = leftStore; recArrange(); // fill in the recursive call arguments } public static boolean isPalindrome(String s) { return isPalindrome(s, 0, s.length() - 1); // call recursive method } private static boolean isPalindrome(String s, int left, int right) { //check if s[left..right] is palindrome; //Part of Homework: supply a base case here // non-base case follows: if (s.charAt(left) == s.charAt(right)) { return isPalindrome(); // fill in recursive call arguments } return false; //s[left] and s[right] are not equal } public static int oddOneOut(int [] A) { //stub for Part D of homework } public static void main(String[] args) { // some test code; can modify this part int [] A = {10, 13, 11, 12, 17}; arrange(A); for (int i = 0; i < A.length; i++) System.out.println(A[i]); System.out.println(isPalindrome("racecar")); System.out.println(isPalindrome("hannah")); System.out.println(isPalindrome("abdaba")); } }