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 38 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


bitingbit

  • Member
  • Posts: 323
Reply 3 on: Yesterday
Wow, this really help

 

Did you know?

Russia has the highest death rate from cardiovascular disease followed by the Ukraine, Romania, Hungary, and Poland.

Did you know?

The U.S. Preventive Services Task Force recommends that all women age 65 years of age or older should be screened with bone densitometry.

Did you know?

About one in five American adults and teenagers have had a genital herpes infection—and most of them don't know it. People with genital herpes have at least twice the risk of becoming infected with HIV if exposed to it than those people who do not have genital herpes.

Did you know?

Astigmatism is the most common vision problem. It may accompany nearsightedness or farsightedness. It is usually caused by an irregularly shaped cornea, but sometimes it is the result of an irregularly shaped lens. Either type can be corrected by eyeglasses, contact lenses, or refractive surgery.

Did you know?

Though Candida and Aspergillus species are the most common fungal pathogens causing invasive fungal disease in the immunocompromised, infections due to previously uncommon hyaline and dematiaceous filamentous fungi are occurring more often today. Rare fungal infections, once accurately diagnosed, may require surgical debridement, immunotherapy, and newer antifungals used singly or in combination with older antifungals, on a case-by-case basis.

For a complete list of videos, visit our video library