Alibabacloud.com offers a wide variety of articles about bubble sort algorithm java, easily find your bubble sort algorithm java information here online.
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+.....
The process of bubbling sorting is to first compare the keywords of the first record with the keywords of the second record, and, in reverse order, Exchange two records and then compare the keywords for the second record and the third record. And so on, until the n-1 record and the nth record's keywords have been compared. The above process is called the first bubbling sort, then the second trip to the previous n-1 the same operation, ...The quick
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
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
Basic idea:
Bubble sort is an exchange sort, and its basic idea is: 22 compare the keywords of adjacent records, if the reverse order is exchanged, until there is no reverse sequence of records. The simplest sort implementation:
Let's take a look at the sort methods that ar
Bubble Sort Method : A record of a small number of keywords is like a bubble stepping up, the key word larger record is like a stone sinking, each trip has one of the largest stones to the bottom.
Algorithmic Nature: (The maximum is the key point, must be put to the last, so the cycle) each time from the first backward scrolling comparison, so that the maximum v
Import java.util.arrays;//=================================================//File name:bubble_sort//------------ ------------------------------------------------------------------//author:common//class Name: arrays_bubble//property://Method: C Lass arrays_bubble{private int[] arrays;private int curnum;public arrays_bubble (int max) {//Create an empty array of Max lengths super (); arrays = new Int[max];curnum = 0;} public void Insert (int value) {//empty array add element arrays[curnum] = value;
Package Suanfa;public class Maopao {public static void main (string[] args) {//TODO auto-generated method stubint[] A = { 3, 2, 1};int temp;int n = a.length;//Compare n-1 big round for (int i = 0; i "Java algorithm" bubble sort
first, the basic idea:
Bubble sort is a simple sort of commutative class. The basic idea is to scan the elements that are to be sorted from scratch, to compare the adjacent elements in sequence during the scan, and to move the elements of the key value back. After each trip, the element with the largest key value is moved to the end, and the position of the elem
Public classMaopao { Public Static voidMain (string[] args) {int[] Array = {332,94,65,4,15,64,16,5,4}; inttemp = 0 ; /*** I:0-8 9 * First time: I=0 the inner for should loop 8 times so the number is **/ for(intI =0; i){ for(intj = 0; J ) { if(array[j]>array[j+1]) {temp=Array[j]; ARRAY[J]= Array[j+1]; Array[j+1] =temp; } } } for(intK:array) {System.out.println (k); } }}I directly use the
The first is the Eightalgorithms.java file, the code is as follows:Import java.util.arrays;/* * Implements eight commonly used sorting algorithms: Insert sort, bubble sort, select sort, Hill sort * and quick sort, merge
Original from http://www.cnblogs.com/kkun/archive/2011/11/23/bubble_sort.htmlClassic 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
Classic Sort algorithm-bubble sort bubble sort
The 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 exchan
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 beginni
, both of which are good for inserting the sort. The code for the hill sort is as follows: Public classShell { Public Static voidsort (comparable[] a) {intn=a.length; intK=1; while(K; while(k>=1) { for(inti=k;i) { for(intJ=i;j>=kless (A[j],a[j-k]); j-=k) {exch (a,j,j-k); }} k=k/3; Continuously decreases k, when K is 1, is insert sort
Classic Sort algorithm-bubbling sort bubble sort
The principle is that the proximity of the number 22 is compared, in order from small to large or from large to small,
After such a trip, the largest or smallest number was exchanged to the last one,
And then start from the
Basic ideasIf the order is sorted from small to large, the sorted array is traversed, and if the current value is greater than the subsequent value then it is exchanged and traversed continuously until no exchange action occurs. The best time for bubbling sorting is O (n), and the worst time complexity is O (N2), so the average time complexity of the bubble sort is O (N2), and the
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.