/**
*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 bubbling sort has three record values, two of which point to two objects that need to be compared, one pointing to the end value of the numeric value that needs to be sorted.In,in+1,out Public classArraybub {Private Longa[]; Private intNelems; PublicArraybub (intmax) {a=New Long[Max]; Nelems=0; } Public voidInsertLongvalue) {A[nelems]=value; Nelems++; } Public voiddisplay () { for(intj=0;j) {System.out.print (A[j]+" "); } System.out.println (); } //How to
Bubble SortBubble sort is to compare the adjacent two numbers each time, (from small to large) if the front number is larger than the number behind, then exchange, otherwise do not exchange;var arr = [11,12,14,9,10,99,22,7]; Array.prototype.bubbleSort = function () {for (var i = 0; i Quick Sort(1) The Selection datum (2) is less than the base number exists on the left, greater than the existence of the right (3) recursive entire functionfunction Qui
Package Day04;public class Shuzu_maopaopaixu_05 {/** bubble sort: The next two elements are compared if the first loop matches the conditional transposition: The most value appears in the last bit */public the static void main ( String[] args) {//TODO auto-generated method Stubint [] Arr={3,2,1,6,9,4};bubblesort (arr);p Rintarray (arr);} public static void Bubblesort (int. [] arr) {for (int. i=0;i 7. Bubble
Simple sorting (after learning to review in time, otherwise like not to learn the same, andSpend more time in the future)Bubble sort: small number upBubble sort (bubblesort) is a repeated visit to the sorted sequence,Compare two elements at a time, if they are in the wrong order, just put them onSwap them over. The work of the sequence of visits is repeated until no more need to be exchanged, that is, the sequence is sorted.Principle:1. Compare adjace
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.