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

Write a program that implements a method that receives an array parameter and so

ID: 3631381 • Letter: W

Question

Write a program that implements a method that receives an array parameter and sorts that array using the bubble-sort algorithm. The bubble-sort algorithm makes several passes through the array. On each pass, successive neighboring pairs are compared. If a pair is in decreasing order, its values are swapped: otherwise, the values remain unchanged. The technique is called a bubble sort because the smaller values gradually "bubble" their way to the top.

The algorithm may be described as follows:

boolean changed;

do{

changed = false;

for(int i = 0; i < list.length - 1; i++){

if(list[i] > list[i + 1]){

swap list[i] with list[i + 1];
changed = true;
}
}
}while(changed);

Continue to properly document your source code. Write this program as if you were explaining it to someone new to arrays. Fully document your code in such a way newcomers to Java will understand and be able to implement a Java array. Your grade on this assignment will be based on your thoroughness of documentation as well as you correctness of code.

Compile and run your program until it works and the output looks nice. Add the necessary documentation as described in Course Documents, and then attach your .java file to this assignment. Do not attach the .class file, attach only the .java source code.


Explanation / Answer

please rate - thanks

message me if any problems

import java.util.*;
public class sorts
{public static void main(String[] args)
   {int temp,i,j,n;
    int [] a = {15,3,5,17,22,93,18};
    bubble(a);
   }
public static void bubble(int num[])
{int j,temp;
boolean changed;
print(num,"before bubble");
do
{changed=false;
for(j=0;j<num.length-1;j++)
     {if(num[j]>num[j+1])   
          {temp = num[j];           
           num[j] = num[j+1];
           num[j+1] = temp;
           changed=true;          
           }
        }
     }while (changed);
print(num,"after bubble");     
}
public static void print(int a[],String mess)
{int i;
System.out.println(mess);
for(i=0;i<a.length;i++)
   System.out.print(a[i]+" ");
System.out.println();
return;
}
}

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