subject

The bubble sort algorithm shown in this chapter is less efficient than it could be. If a pass is made through the list without ex- changing any elements, this means that the list is sorted and there is no reason to continue. Modify this algorithm so that it will stop as soon as it recognizes that the list is sorted. Do not use a break statement! Make it to where it compiles succesfully. Thanks Program:
public class bubblesort
{
public static void bubbleSort (Comparable[] data, int maxlength)
{
int position, scan;
Comparable temp;
for (int i = maxlength-1; i >= 1; i--)
{
for (scan = 0; scan <= maxlength-i ; scan++)
{
if (data[scan].compareTo(data[scan+i]) > 0)
{
// Swap the values
temp = data[scan];
data[scan] = data[scan + i];
data[scan + i] = temp;
}
}
}
}
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 12:30
What characteristic of long period comets suggest they come directly from the oort cloud?
Answers: 2
question
Computers and Technology, 22.06.2019 13:00
Write a program which asks you to enter a name in the form of first middle initial last. so you might enter for example samuel p. clemens. use getline to read in the string because it contains spaces. also, apparently the shift key on your keyboard doesn’t work, because you enter it all lower case. pass the string to a function which uses .find to locate the letters which need to be upper case and use toupper to convert those characters to uppercase. the revised string should then be returned to main in the form last, first mi where it will be displayed.
Answers: 1
question
Computers and Technology, 22.06.2019 16:20
Consider the following statements, then select one of the answers below: the signal() function shown below registers "sig_handler()" as the signal handler function for the sigkill signal, without the complexity of using when the sigkill signal is sent to a process running this code, by a user typing "kill -kill ", where the correct process id is used for to target the process, sig_handler() will be executed.
Answers: 1
question
Computers and Technology, 23.06.2019 18:30
Write a program that prints the day number of the year, given the date in the form month-day-year. for example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. the program should check for a leap year. a year is a leap year if it is divisible by 4, but not divisible by 100. for example, 1992 and 2008 are divisible by 4, but not by 100. a year that is divisible by 100 is a leap year if it is also divisible by 400. for example, 1600 and 2000 are divisible by 400. however, 1800 is not a leap year because 1800 is not divisible by 400.
Answers: 3
You know the right answer?
The bubble sort algorithm shown in this chapter is less efficient than it could be. If a pass is mad...
Questions
question
French, 25.02.2021 15:00
question
Mathematics, 25.02.2021 15:00
question
French, 25.02.2021 15:00
Questions on the website: 13722367