Bubble Sort:
bubble Sorting is one of the most commonly used and the most introductory array sorting algorithms, and it sorts the elements of an array by always putting decimals forward, large numbers back, similar to the action of bubbles going up in water, so called bubbling sort. For example:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/A7/82/wKioL1nndKHSera5AA2-vhNfbGQ394.png "style=" float : none; "title=" vip14-end bowl blowing Water-14th Section -1.8121.png "alt=" Wkiol1nndkhsera5aa2-vhnfbgq394.png "/>
bubbling sorting has multiple ways of writing, which is one way. The bubbling algorithm is implemented by a two-tier loop, in which the outer loop is used to control the number of sort wheels, usually minus one for the length of the array to be sorted, since only one array element is left in the last loop, no contrast is needed, and the array is sorted. The inner loop is used primarily to compare the size of each adjacent element in the array to determine whether to swap the position, and the number of comparisons and exchanges decreases with the sort wheel count. The last side takes the value out of a traversal, and can be used for loops or for each loop.
Basic idea:
The basic idea of bubble sorting is to compare the values of adjacent elements, to exchange element values if conditions are met, to move the smaller elements to the front of the array, to move the large elements behind the array (that is, to swap the positions of two elements) so that the smaller elements rise from the bottom to the top as bubbles.
Two-dimensional arrays:
Two-dimensional array is also an array of arrays, two-dimensional arrays are often used to represent the table, the table of information in the form of rows and columns organized, in the game is generally used to do 2D maps, in the late application although not too broad, but also need to understand the master, The first [] subscript in a two-dimensional array represents the row where the element is located, and the second [] subscript represents the column in which the element resides. For example:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/08/D2/wKiom1nnd1ngCcvTAAXd2nciYh4022.png "style=" float : none; "title=" vip14-end bowl blowing Water-14th Section -1.8555.png "alt=" Wkiom1nnd1ngccvtaaxd2nciyh4022.png "/>
Two-dimensional arrays are commonly used for proper declaration:
1.int[] [] i=new int[[]; declares an empty two-dimensional array with an int type identifier of i
2.int[] [] i=new int[3][3]; declares a two-dimensional array with an int type identifier of i, a line length of 3, and a column length of 3
3.int[] [] i={{23,3,4},{42,45,67},{75,43,23}}; declares an int type identifier of i, a line length of 3, a column length of 3, And initializes a two-dimensional array that gives the parameter values
4.int[] [] i=[] []{{23,3,4},{42,45,67},{75,43,23}}; declares an int type identifier of i, a line length of 3, a column length of 3, And initializes a two-dimensional array that gives the parameter values
5.int I []; declares an empty two-dimensional array with an int type identifier of i
6.int i=3;
int j=3;
Int[][] Number=new int[i][j]; declares an int type with the identifier number, defines the length of the line with the value of the variable i , and uses the variable j value to define the length of the column.
A two-dimensional array traversal needs to be nested in a loop. For example:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/08/D2/wKiom1nnd2GCkRtmAA4v3DmNraY808.png "style=" float : none; "title=" vip14-end bowl blowing Water-14th Section -1.81072.png "alt=" Wkiom1nnd2gckrtmaa4v3dmnray808.png "/>
For each loop nesting can also be traversed. For example:
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/A7/82/wKioL1nndLWR7jvsABBD91OPy9w915.png "style=" float : none; "title=" vip14-end bowl blowing Water-14th Section -1.81099.png "alt=" Wkiol1nndlwr7jvsabbd91opy9w915.png "/>
This article is from the "12831981" blog, please be sure to keep this source http://12841981.blog.51cto.com/12831981/1973990
Java array bubble sort and two-dimensional array