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
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
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
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
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
/** 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
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
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
/**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
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
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; -
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
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
/**
*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);
}
}
/*
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.