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 45 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
Great answer, keep it coming :)


xthemafja

  • Member
  • Posts: 348
Reply 3 on: Yesterday
:D TYSM

 

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?

Acetaminophen (Tylenol) in overdose can seriously damage the liver. It should never be taken by people who use alcohol heavily; it can result in severe liver damage and even a condition requiring a liver transplant.

Did you know?

It is believed that humans initially contracted crabs from gorillas about 3 million years ago from either sleeping in gorilla nests or eating the apes.

Did you know?

Chronic necrotizing aspergillosis has a slowly progressive process that, unlike invasive aspergillosis, does not spread to other organ systems or the blood vessels. It most often affects middle-aged and elderly individuals, spreading to surrounding tissue in the lungs. The disease often does not respond to conventionally successful treatments, and requires individualized therapies in order to keep it from becoming life-threatening.

Did you know?

Hypertension is a silent killer because it is deadly and has no significant early symptoms. The danger from hypertension is the extra load on the heart, which can lead to hypertensive heart disease and kidney damage. This occurs without any major symptoms until the high blood pressure becomes extreme. Regular blood pressure checks are an important method of catching hypertension before it can kill you.

For a complete list of videos, visit our video library