The instructions to answer my question are below in bulletpo
The instructions to answer my question are below in bulletpoints, and write the code in Java, thank you.
A classic 0(N^2) algorithm is Bubble Sort, where a loop insicle of a loop is used to sort the data Write a Bubble Sort for the array of integers theArray that orders them low to high Use the variable outvar on the outer loop, start the target position at the end of the array and move backwards Use the variable innerval on the inner loop, start the beginning of the array and move towards the outer target Do not write a separate swap method, code the swap inside the inner loop using the variable temp Do not declare or initialize theArray, do not declare outvar. innerval, temp it will be done for you Write only the 2 loops with an if inside them that does the swapSolution
for(outvar=theArray.length-1;outvar>-1;outvar--){
for(interval=0;interval<outvar;interval++){
if(theArray[outvar]<theArray[interval]){
temp = theArray[outvar];
theArray[outvar] = theArray[interval];
theArray[interval] = temp;
}
}
}
/* sample output
array = {5,4,3,2,1}
1 2 3 4 5
*/
