Modify the bubble sortcode given below to implement gap sort. public static void
ID: 3609251 • Letter: M
Question
Modify the bubble sortcode given below toimplement 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
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.