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 43 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
:D TYSM


ASDFGJLO

  • Member
  • Posts: 335
Reply 3 on: Yesterday
Great answer, keep it coming :)

 

Did you know?

People about to have surgery must tell their health care providers about all supplements they take.

Did you know?

More than one-third of adult Americans are obese. Diseases that kill the largest number of people annually, such as heart disease, cancer, diabetes, stroke, and hypertension, can be attributed to diet.

Did you know?

Atropine, along with scopolamine and hyoscyamine, is found in the Datura stramonium plant, which gives hallucinogenic effects and is also known as locoweed.

Did you know?

Throughout history, plants containing cardiac steroids have been used as heart drugs and as poisons (e.g., in arrows used in combat), emetics, and diuretics.

Did you know?

Although not all of the following muscle groups are commonly used, intramuscular injections may be given into the abdominals, biceps, calves, deltoids, gluteals, laterals, pectorals, quadriceps, trapezoids, and triceps.

For a complete list of videos, visit our video library