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 36 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
Gracias!


samiel-sayed

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

 

Did you know?

A good example of polar molecules can be understood when trying to make a cake. If water and oil are required, they will not mix together. If you put them into a measuring cup, the oil will rise to the top while the water remains on the bottom.

Did you know?

Warfarin was developed as a consequence of the study of a strange bleeding disorder that suddenly occurred in cattle on the northern prairies of the United States in the early 1900s.

Did you know?

The FDA recognizes 118 routes of administration.

Did you know?

The term bacteria was devised in the 19th century by German biologist Ferdinand Cohn. He based it on the Greek word "bakterion" meaning a small rod or staff. Cohn is considered to be the father of modern bacteriology.

Did you know?

Today, nearly 8 out of 10 pregnant women living with HIV (about 1.1 million), receive antiretrovirals.

For a complete list of videos, visit our video library