The bubbling algorithm, as its name implies, is the data arranged in a certain order.Algorithm ideas:Suppose there is an array of suchInt[] arr = {5, 9, 3, 1, 2, 6, 7, 4, 8};According to the algorithm definition, the output we need isInt[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};First, get our original array. Determine the size of arr[0] and arr[1] first. If ARR[0]>ARR[1], their location is exchanged. Then compare the sizes of arr[1] and arr[2], and if arr[1]>arr[2], swap their positions. And so on, a
The so-called array, is the same data type of elements in a certain order of the set, that is, the finite data type of the same variable with a name, and then use the number to distinguish their variable collection, the name is called the array name, the number is called subscript.Each variable that makes up an array is called the component or element of the array.The index of the elements in the array starts with 0, which is a "0", a "1" ....Quote: Bubble
This article mainly introduced JS from the bottom upward rising bubble effect, examples of javascript operation of mouse events, pictures and styles related skills, the need for friends can refer to the
The example of this article tells the JS from the bottom upward rising bubble effect method. Share to everyone for your reference. The implementation methods are as follows:
?
1 2 3 4 5 6 7 8
/** 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 generic parameter must pass a reference type.D
Bubble sort, as the name implies, according to certain rules, the data has been dischargedDirectly on the code1 ImportRandom2 3 defbubblesort (data):4Change=True5 forIinchRange (len data) -1,1,-1):6 forJinchRange (0,i):7 ifDATA[J] > Data[j+1]:8Data[j],data[j+1]=data[j+1],data[j]9Change=FalseTen ifChange : One Break A -Data=[random.randint (1,1000) forIinchRange (1000)] - Print(data) the bubblesort (data)
/**
*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);
}
}
/*
Bubble Sort:is to compare the next two elements by index, if greater than/less than (depending on the need to ascending or descending order), then displace, otherwise do not changeSuch a round down, compared n-1 times, n equals the number of elements; n-2, n-3 ... Until the last round, compared 1 timesSo the number of comparisons is decremented: from n-1 to 1Then the total number of comparisons is: 1+2+3+...+ (n-1), calculated in a linear formula: (1+
Core tip: This flash example produced an interesting "clown blowing bubble" animation, mainly using the Oval, line tool, as well as arbitrary deformation and gradient fill, and so on, easy to understand, suitable for practice.
This flash example produced an interesting "clown bubble" animation, mainly using ellipses, line tools, as well as arbitrary deformation and gradient fill, and so on, easy to underst
Bubble sort principle: For an array of all elements of 22 comparison, occurs greater than the transformation array subscript is ascending sort, occurs less than the transformed data subscript is descending sortFor example, given an array of [1,-2, 3,-4], for our requirements, 22 compared to the subscript transformation is ascending, after the first comparison, the maximum value of 3 will be moved to the rightmost array, the entire array of comparisons
Bubble sort: Classic algorithm problem.There is a set of numbers 2,10,8,20,11, which arranges the numbers in order from large to small. 20,11,10,8,22,10,8,20,11Find the maximum number and put it in the first place (1,2,3,4,5)20,10,8,2,11From the remaining 4 numbers, find the largest (2,3,4,5)20,11,8,2,10From the remaining 3 numbers, find the largest (3,4,5)20,11,10,2,8From the remaining 2 numbers, find the largest (4,5)20,11,10,8,2Above is the teacher
/** Idea 1: Bubble sort* 22 comparison, if the front is greater than the back then I will let them exchange positions;* */function sortbubble (ary) { for (var i = 0; i Number of rounds to compare for (var j = 0; J 22 comparison var temp = ary[j]; if (Ary[j] > ary[j+1]) { ARY[J] = ary[j+1]; ARY[J+1] = temp; } } } return ary;}var temp = sortbubble
The working mechanism of the insertion sort and the arrangement of the rows in the hand when playing cards are similar. In the beginning, our left hand is empty, the ranking is down on the table, then, one hand from the table to touch a card, and put it in the right hand row of the correct position. In order to find the correct position of this card, he and his hands do not have a oh from the right to the left to compare, no matter what time, the left hand in the cards are in good order. (derive
1 Public classBubblesorttest {2 //Bubble Sort3 Public Static voidBubblesort (int[] source) {4 //the outer loop controls the number of traversal times, the number of n is sorted, and the n-1 is traversed5 for(inti = source.length-1; i > 0; i--) {6 //each traversal is completed, the element labeled I is determined, and the next traversal is no longer participating in the comparison7 for(intj = 0; J ) {
Reference article:http://blog.csdn.net/it_zjyang/article/details/53406764http://blog.csdn.net/hacker00011000/article/details/52176100Bubble sort (Bubble sort)principle : Compare two adjacent elements in turn, exchanging large value elements to the right end. First, the 1th and 2nd numbers are compared, the decimals are placed before the large number is placed. And so on Until all sorts are complete. N number to sort complete, a total of N-1 , the numb
of comparisons, and the 11th line for loop controls the number of I (minimum or maximum) and the remaining number of comparisons2. Bubble sortThe principle is that the adjacent number 22 is compared, in order from small to large or from large to small to exchange,After such a trip, the largest or smallest number was exchanged to the last,And then start from the beginning to the 22 comparison exchange, until the end of the second placecode example:1
Bubble sort implemented with Go languagePackage Bubblesortfunc Bubblesort (values []int) {flag: = Truefor I, size: = 0, Len (values); i This article is from the "Van Star Technology Blog" blog, please be sure to keep this source http://ustb80.blog.51cto.com/6139482/1575232Golang Bubble Sorting algorithm
An array is a combination of data of a data type. An entity in an array is called an element or member of an array.Example one: creation and extraction of dataExample two: How to create and assign an arrayExercise One: Enter the age of nine people into an array from the consoleExercise two: Seeking the sum of agesExercise three: Seeking the sum of Ages, method twoExercise Four: Enter the number of classes, according to the number of people to enter the results, to find the average scoreExercise
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.