Write a program that implements a method that receives an arrayparameter and sor
ID: 3618119 • Letter: W
Question
Write a program that implements a method that receives an arrayparameter and sorts that array using the bubble-sort algorithm. Thebubble-sort algorithm makes several passes through the array. Oneach pass, successive neighboring pairs are compared. If a pair isin decreasing order, its values are swapped: otherwise, the valuesremain unchanged. The technique is called a bubble sort because thesmaller values gradually "bubble" their way to the top.
The algorithm may be described as follows:
booleanchanged;
do{
changed =false;
for(int i = 0;i < list.length - 1; i++){
if(list[i] > list[i + 1]){
swaplist[i] with list[i + 1];
changed = true;
}
}
}while(changed);
Explanation / Answer
please rate - thanks import java.util.*; public class bubblesort {public static void main(String[] args) {int i,j; Scanner input = new Scanner(System.in); Random gen = newRandom(); int num[]=newint[20]; //array has 20 elements for(i=0;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.