This topic contains a solution. Click here to go to the answer

Author Question: Fill in the code to complete the following method for sorting a list.public static void ... (Read 37 times)

joe

  • Hero Member
  • *****
  • Posts: 627

Question 1

Fill in the code to complete the following method for checking whether a string is a palindrome.

public static boolean isPalindrome(String s) {
return isPalindrome(s, 0, s.length() - 1);
}

public static boolean isPalindrome(String s, int low, int high) {
if (high <= low) // Base case
return true;
else if (s.charAt(low) != s.charAt(high)) // Base case
return false;
else
return ________;
}

◦ isPalindrome(s)
◦ isPalindrome(s, low + 1, high)
◦ isPalindrome(s, low + 1, high - 1)
◦ isPalindrome(s, low, high - 1)
◦ isPalindrome(s, low, high)

Question 2

Fill in the code to complete the following method for sorting a list.

public static void sort(double[] list) {
________;
}

public static void sort(double[] list, int high) {
if (high > 1) {
// Find the largest number and its index
int indexOfMax = 0;
double max = list[0];
for (int i = 1; i <= high; i++) {
if (list[i] > max) {
max = list[i];
indexOfMax = i;
}
}
// Swap the largest with the last number in the list
list[indexOfMax] = list[high];
list[high] = max;
// Sort the remaining list
sort(list, high - 1);
}
}

◦ sort(list, list.length)
◦ sort(list)
◦ sort(list, list.length - 1)
◦ sort(list, list.length - 2)


Related Topics

Need homework help now?

Ask unlimited questions for free

Ask a Question
Marked as best answer by joe on May 6, 2020

flexer1n1

  • Sr. Member
  • ****
  • Posts: 373
Lorsum iprem. Lorsus sur ipci. Lorsem sur iprem. Lorsum sur ipdi, lorsem sur ipci. Lorsum sur iprium, valum sur ipci et, vala sur ipci. Lorsem sur ipci, lorsa sur iprem. Valus sur ipdi. Lorsus sur iprium nunc, valem sur iprium. Valem sur ipdi. Lorsa sur iprium. Lorsum sur iprium. Valem sur ipdi. Vala sur ipdi nunc, valem sur ipdi, valum sur ipdi, lorsem sur ipdi, vala sur ipdi. Valem sur iprem nunc, lorsa sur iprium. Valum sur ipdi et, lorsus sur ipci. Valem sur iprem. Valem sur ipci. Lorsa sur iprium. Lorsem sur ipci, valus sur iprem. Lorsem sur iprem nunc, valus sur iprium.
Answer Preview
Only 49% of students answer this correctly




joe

  • Member
  • Posts: 627
Reply 2 on: May 6, 2020
Excellent


brbarasa

  • Member
  • Posts: 308
Reply 3 on: Yesterday
Thanks for the timely response, appreciate it

 

Did you know?

Common abbreviations that cause medication errors include U (unit), mg (milligram), QD (every day), SC (subcutaneous), TIW (three times per week), D/C (discharge or discontinue), HS (at bedtime or "hours of sleep"), cc (cubic centimeters), and AU (each ear).

Did you know?

You should not take more than 1,000 mg of vitamin E per day. Doses above this amount increase the risk of bleeding problems that can lead to a stroke.

Did you know?

The human body produces and destroys 15 million blood cells every second.

Did you know?

Medications that are definitely not safe to take when breastfeeding include radioactive drugs, antimetabolites, some cancer (chemotherapy) agents, bromocriptine, ergotamine, methotrexate, and cyclosporine.

Did you know?

According to the FDA, adverse drug events harmed or killed approximately 1,200,000 people in the United States in the year 2015.

For a complete list of videos, visit our video library