Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the bubble sortcode given below to implement gap sort. public static void

ID: 3609251 • Letter: M

Question

Modify the bubble sortcode given below to
implement gap sort. public static voidbubbleSort (Comparable[] data, int maxlength)
{
int position, scan;
Comparable temp;
for (position = maxlength; position >= 1; position--)
{
for (scan = 0; scan <= position – 1; scan++)
{
if (data[scan].compareto(data[scan+1]) > 0)
{
// Swap the values
temp = data[scan];
data[scan] = data[scan + 1];
data[scan + 1] = temp;
}
}
}
} Modify the bubble sortcode given below to
implement gap sort. public static voidbubbleSort (Comparable[] data, int maxlength)
{
int position, scan;
Comparable temp;
for (position = maxlength; position >= 1; position--)
{
for (scan = 0; scan <= position – 1; scan++)
{
if (data[scan].compareto(data[scan+1]) > 0)
{
// Swap the values
temp = data[scan];
data[scan] = data[scan + 1];
data[scan + 1] = temp;
}
}
}
}

Explanation / Answer

Sample code for Shell Sort

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote