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 ) {
The first is the algorithm implementation file Sort.h, the code is as follows:/** implements eight commonly used sorting algorithms: Insert sort, bubble sort, select sort, Hill sort * and quick sort, merge
One. Bubble sortHere is another sort of method, the bubbling sort method. The choice of sorting method is closer to people's normal thinking, one data and the rest say there is data comparison.Bubble sorting method is the adjacent data between the comparison, the big data on the right, the angle of 1-2 data comparison, angle 2-3 data comparison ...Whether you cho
1. Printingprint--printing, no line break, add line breaks as requiredprintln--Print once and wrap it up.printf--printing, inherit C speech format, can be formatted outputLine break' \ R ' is a carriage return, ' \ n ' is a newline, ' \ t ' is a tabMethod of use: 1. SYSTEM.OUT.PRINTLN ("Thank you for your support \ n");2.SYSTEM.OUT.PRINTLN (i+ "*" +j=i*j+ "\ n");2. Bubble sortUsed for array sorting, comparing the first and neighboring elements, sequen
Bubble Sort:Is two elements that are contiguous by index, assuming greater than/less than (depending on whether an ascending or descending row is required). Then replace, or not change.Such a round down. Compare n-1 times. n equals the number of elements; n-2, n-3 ... Until the last round. 1 more times.So the comparison is decremented: from n-1 to 1Then the total number of times is: 1+2+3+...+ (n-1), calculated in a linear formula: (1+n-1)/2* (n-1) ==
Classic Sort algorithm-bubble sort 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 e
packageorg.rev.algorithm;/*** bubble sort, complexity O (n^2), as follows:**1. compare adjacent elements. If the first one is bigger than the second one, swap them both. **2. does the same for each pair of adjacent elements, starting with the last pair from the first pair to the end. **3. After this step is done, the final element will be the largest number. **4. Repeat the above steps for all elements, exc
Bubble sort (Bubble sort) is a simple sort algorithm. Each time the adjacent two numbers are compared, they are exchanged if their positions do not match.Each comparison, the number of comparisons will be reduced one time, because the previous is better.For example:First tim
Bubble sort (Bubble sort) is a sort of interchange, the basic idea : 22 compare the keywords of adjacent records, if the reverse order is exchanged, until there is no reverse sequence of records.
The following is the code for the implementation:
public class Bubbleso
The basic idea of bubbling (Bubble sort) is: consider arrays to be sorted from top to bottom, with smaller keywords as lighter, larger keywords as heavier, smaller keyword values as bubbles in the water to float, larger keywords like rocks in the water to sink. , the sort ends when the bubbles are floating in the appropriate position.
Algorithm performance analy
The code is as follows:public class Bubblesort {public static void Bubblesort (Datawrap [] data) {System.out.println ("start sort"); int length = Data.len gth;for (int i = 0;i Java Bubble sort
Description: Welcome to criticize correct, message praise! If reproduced, please specify the original address: http://www.cnblogs.com/chris0710/p/8995234.htmlThis article will explain the bubble sort principle by simple example, gossip less, direct on the code.1 /**2 * Bubble Sort3 * 4, 6, 2, 3, 54 * Idea: Write the inner Loop first (number of times = arr.length-
1. Core idea of bubbling algorithmThe core idea of bubble sorting is to scan the data list, find the two contiguous data in the order of 22 compare and swap the location, then continue to scan the data, and then repeat the above operations repeatedly until the end of the sorting.2. ExampleWe take the 23,15,58,-4,99,0 of this unordered set of numbers as an example: from small to large,Initial state: 23,15,58, -4,99,0First sorted results: 15,23,-4,58,0,
Bubble Sort:
is to compare adjacent two elements by index, if greater than/less than (depending on whether ascending or descending order is required), replace, or do not changeSuch a round down, comparing the 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 decreasing: from n-1 to 1Then the total number of comparisons is: 1+2+3+.....
Copy Code code as follows:
/**
* Principle:
* for n cycles, each cycle from the back forward to the adjacent two elements of the comparison, small forward, big back
*
* Time Complexity:
* Average condition: O (n^2)
* Best case: O (n)
* Worst case: O (n^2)
*
* Stability: Stable
**/
public class bubble sort {
public int[] Bubblesort (int[] A, int n) { for (int i =
http://www.verejava.com/?id=16992682424030 /* Using the bubbling algorithm: arrays the score from small to large sort output idea: The first order of 1. Compares the n elements of an array from the first element to the following elements 2. If the previous data is larger than the data behind it, the two switching positions until the loop is complete, that The largest data in the array will be in the last position of the array. The first order of 3.
Package WMK;Import Java.util.Scanner;public class Maopaopaixu {Public Maopaopaixu () {}public void Maxtomin () {Get console input with scannerScanner sc = new Scanner (system.in);SYSTEM.OUT.PRINTLN ("Please input String:");String s = sc.nextline ();int len = S.length ();int ints[] = new Int[len];into an arrayfor (int i = 0; i Ints[i] = integer.valueof (s.substring (i, i + 1));}Core codeMethod One: The comparison of two adjacent elements, to the tail of the closerfor (int i = 0; i for (int j = i
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.