bubble sort java

Discover bubble sort java, include the articles, news, trends, analysis and practical advice about bubble sort java on alibabacloud.com

The bubble sort of Java classic algorithm

1 /**2 * Bubble Sort (the current value is compared to the next value in turn)3 */4 Public classBubblesort5 {6 Public Static voidMain (string[] args)7 {8 sort ();9 }Ten Public Static voidsort () { One A int[] arr =New int[]{80,15,31,20,59}; - - for(inti=1;i){ the for(intj=0;j){ - if(arr[j]>arr[j

Java Bubble sort

Bubble sort//From first start two number to size then swap position classmaopao{publicstaticint[] sort (Int[]array) {for (int i=0;i Java Bubble sort

Java Basic Learning Summary Five (recursive algorithm, bubble sort)

One: Recursive algorithmConcept: Call your own methodThe sample code is as follows:1 @Test2 /**3 * Recursive summation4 * 5+4+3+2+1=155 */6 Public voidgetsum () {7 Longsum = SUM (5);8System.out.println ("sum=" +sum);9 }Ten One Public Static LongSuminti) { A if(1 = =i) { - return1; -}Else { the returni + SUM (i-1); - } -}Explain:When I=5, return to 5+sum (4),When i=4, return to 4+sum (3),When I=3, return to 3+sum (2),When i=2

Java's bubble sort

Bubble sort: can be imagined as boiling water, bubbles at the bottom of the bottle is relatively small, reached the water when the maximum.Bubble sort idea: first determine whether ascending or descending, here ascending as an example. Each two adjacent numbers are compared, the previous number is larger than the next one, the two digits are exchanged, otherwise

Java Bubble sort

PackageCom.hanqi;ImportJava.util.Scanner; Public classZUOYEMAOPAOPAIXV { Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); System.out.println ("Please enter the number to sort:"); Scanner v=NewScanner (system.in); intGeshu =V.nextint (); intarr[]=New int[Geshu]; for(intA = 0; A ) {System.out.println ("Please enter" + (a+1) + "number:"); Arr[a]=V.nextint (); } for(intd=1; D) { for(intb = 1; b) {

The seventh day of the JAVA faltering self-study array selection bubble sort optimization

the permutation of all the data including two equal numbersYou can only replace two different numbers, otherwise the operation will be faulted. If you want to use this method to complete, you must add the first condition judgment. if (x!=y)The former joins this judgment can reduce two equal data permutation, does not join also does not have the error, only then wasted the unnecessary system resources expense. While the latter wastes system resources, it also calculates errors. So if the judgmen

Java Bubble sort

Import Java.util.Scanner;public class maopaopaixu{public static void Main (String [] args) {Scanner s= New Scanner (system.in);//Get keyboard input valuesInt[] x= new int[10];//declaring an array variablefor (int m=0;mX[m]=s.nextint ();//loop gets the array value of the keyboard input;}Int[] x= new int[5]; Declares and initializes an array;x[0]=1065;x[1]=15;x[2]=43656;x[3]=1757;x[4]=56;Int[] x= new int[]{1,2,3,4,5};int temp,i,j;for (i=0;ifor (j=0;jif (X[j]>x[j+1]) {TEMP=X[J];X[J]=X[J+1];X[j+1]=t

Java Bubble sort

First, from small to large:Code:public class Demothree {Static double[] Sort (double[] nums) {Double temp=0;//Temporary variableStart sortingfor (int i = 0; i for (int j = 0; J if (Nums[j]>nums[j+1]) {TEMP=NUMS[J+1];NUMS[J+1]=NUMS[J];Nums[j]=temp;}}}return nums;}public static void Main (string[] args) {Double[] n={1,5,4.5,6.5,1.5,3.0};System.out.println ("Pre-order");for (double d:n) {System.out.print (d+ "\ t");}System.out.println ("\ n--------------

Bubble sort Algorithm (Java implementation)

public class hellojava{public static void Main (string[] args) {int[] arr1 = new int[] {20,40,90,30,80,70,50};Bubblesort (ARR1);int[] arr2 = new int[] {11,52,4,5,65,4,2,1,45};Bubblesort (ARR2);}public static void Bubblesort (int[] array) {System.out.println ("Before sorting:");for (int i=0; iSystem.out.print (array[i]+ "");}System.out.print ("\ n" + "bubble sort after:" + "\ n");int flag;for (int i=1; iFlag

Java Bubble Sort Method upgrade version

/** Upgraded version of bubble sort, can compare integer array, decimal type array** */public static T temp;for (int i = 0; i for (int j = 0; J if (Arr[j + 1].compareto (Arr[i]) temp = arr[j + 1];Arr[j + 1] = Arr[j];ARR[J] = temp;}}}System.out.println ("Sorted array is:" + arrays.tostring (arr));}Method invocation:Integer arrint[] = {10, 2, 6, 9, 8}; An array needs to be defined as a reference type, and a g

Java Bubble sort

Bubble sort ——— Array (int []array)650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/89/42/wKioL1gN7HOymTewAAFjK2N9VsQ893.png-wh_500x0-wm_3 -wmp_4-s_25889069.png "title=" Qq20161024162258.png "alt=" Wkiol1gn7hoymtewaafjk2n9vsq893.png-wh_50 "/>/* Bubble sort implementation (1) Find the maximum value in the arra

C # Insert Sort bubble Sort Select sort High speed sort heap sort merge sort base Sort Hill sort

C # Insert Sort bubble Sort Select sort High speed sort heap sort merge sort base Sort Hill sortThe following is a list of eight basic sorts

Java Bubble sort

Today suddenly want to write their own bubble sort, did not expect to suppress a half-day did not want to come out, the original many seemingly simple things, I do not refer to other very difficult to come out. I finally figured it out.The post code is recorded:Package com.baidu.www Public classBubble { Public Static voidMain (string[] args) {int[] num = { A,3, the, -, the,6, the, the }; inttemp =0; for(in

Bubble sort-java Implementation

/**Function: Bubble sort, from small to large output.Thought: The first round is compared from the first number until the largest number is put to the last, the second round is placed in the penultimate position, and so on.*/public class Demo{public static void Main (string[] args){Int[] B=new int[9];B=new int[]{8,3,6,1,9,5,4,2,7};Bubble_sort (b,9);for (int i=0;i{System.out.print (b[i]+ "");}}public static

Java bubble sort Implementation and formula __java

Video parsing https://edu.csdn.net/course/play/7813 When soldiers queue in a TV series, they are arranged in the order of tall and short, and the taller and taller are compared by 22. Bubble Sort: The basic idea is to repeat the order of the entire array, compare two elements at a time (22 sorted), and then swap them if they do not match, repeating this until the number of numbers is no longer needed (the

Java Bubble sort

1 Public classDemo {2 Public Static voidMain (string[] args) {3 int[] Nums =New int[]{23,56,89,72,36};4 5 /*6 * Outer loop control how many rounds.7 * Internal loop control how many times each round goes8 */9 for(inti=0;i){Ten for(intj = 0; J ) { One //Compare Size A if(nums[j]]){ - //Exchange - inttemp =Nums[j]; theNUMS[J] = nums[j+1]; -NUMS[J+1] =temp; -

Bubble sort (Java)

Look at the code first Public classMain { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub int[] a = {9,5,4,3,7,3,2,1,2};//data range is 0-10 for(inti = a.length-1;i>0;i--){ for(intj=0;j){ if(a[j]>a[j+1]){ inttemp = 0; Temp=A[j]; A[J]=a[j+1]; A[j+1]=temp; } } } for(inti = 0;i) {System.out.println (a[i]); } }}There's one more way. Public classMain { Public Static voidMain (string[] a

Java's bubble sort

Bubble sort because of its simplicity, usually we learn a sort algorithm for all kinds of programming languages first choose to learn1 Public classBubblesort {2 Public Static voidMain (string[] args) {3 //creates an array, which is a random sequence of elements.4 int[] array = {666, 8, 28, 66, 86, 68 };5 //create an object for the bu

Java Bubble sort

Public classBubblesort { Public Static voidMain (string[] args) {intScore[] = {1,4,5,7,2,3,9,0,6,8}; for(inti=1;i//up to do n-1 sort of trip for(intj=0;j//each sort range is reduced if(score[j]]){ //3 ways to cross-line 2 variable data//int temp = score[j];//Score[j] = score[j+1];//score[j+1] = temp;Score[j]= Score[j]^score[j+1]; Score[j+1] = score[j]^score[j+1

Use IntelliJ idea to write a Java bubble sort

/** *created by Xuzili at 9:38 PM on 2/3/2018 */ public class Bubble { public static void Main (string[] args) { Int[] A = new int[]{9, 6, 8, 3, 0, 1}; int I, j, T; for (i = 0; i for (j = 0; J if (A[j] > a[j + 1]) { t = a[j]; A[J] = a[j + 1]; A[j + 1] = t; } for (i = 0; i System.out.print (A[i]); System.out.println ("\ n--------Gorgeous split-line--------"); for (int num:a) SYSTEM.OUT.PRINTLN (num); } } /*

Total Pages: 15 1 .... 7 8 9 10 11 .... 15 Go to: Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.