Import java.util.arrays;//=================================================//File name:bubble_sort//------------ ------------------------------------------------------------------//author:common//class Name: arrays_bubble//property://Method: C Lass arrays_bubble{private int[] arrays;private int curnum;public arrays_bubble (int max) {//Create an empty array of Max lengths super (); arrays = new Int[max];curnum = 0;} public void Insert (int value) {//empty array add element arrays[curnum] = value;curnum++;} public void display () {//display array System.out.println (arrays.tostring (Arrays));} private void Swap (int one,int) {//Interchange int temp = Arrays[one];arrays[one] = Arrays[two];arrays[two] = temp;} public void Bubblesort () {int out,in;for (out=curnum-1;out>0;out--) {//curnum is prepared for the next insert and should be subtracted from 1for (in=0;in< out;in++) {//start with the last number, compare the maximum to the last if (Arrays[in]>arrays[out]) {swap (in,in+1), and the previous number,}}} Main class//function:bubble_sortpublic class Bubble_sort {public static void main (string[] args) {//TODO auto-generated method stub int maxSize = 100; Arrays_bubble Arrays_demo = new Arrays_bubble (maxSize); Arrays_demo.insert (; arrays_demo.insert); Arrays_demo.insert Demo.insert (Arrays_demo.insert); Arrays_demo.display (); Arrays_demo. Bubblesort (); Arrays_demo.display ();}}
Java sorting algorithm--bubble sort