Copy CodeThe code is as follows:
/**
* Bubble Sort Bubble sort
*
* Principle: Multiple cycles are compared, the maximum number is moved to the top at each comparison. Each time you loop, find the maximum value in the remaining variable and then reduce the query range. So after many loops, the
Recommend a Visual Web site "Visual Algo": Url= ' https://visualgo.net/en/sorting 'This website gives the principles and processes of various sorting algorithms, which are visualized through dynamic forms. The related pseudo-code are also given, as well as the specific steps to execute to code."Bubble Sort"You need to repeatedly visit the sequence of columns that need to be sorted. The size of the adjacent
Easy to understand:
Assume that the array length is 8 and the sequence number starts from 0.
1. Insert sorting:
(1) sorting is performed 7 times.
For (INT I = 1; I
For (Int J = I; j> 0; j --)
If (array [J-1]> array [J])
Swap (ref array [J-1], ref array [J]) the switching position ensures that the first I position of the array is sorted in order.
}
(2) duplicate (1 ).
2. Bubble Sorting:
(1) sorting is performed 7 times.
For (IN
Code:1 Packagecom.cn.algorithm_arithmetic algorithm;2 /**3 * This program records the bubble sort of the classical sorting algorithm4 * @authorAdministrator5 *6 */7 8 Public classBubble_sort {9 //bubble sort before optimizationTen Public Static voidBubble_sort (int[] a) { One for(inti = 0
In the previous article, we have introduced two basic sorting methods: Insert sort and select sort. Today's introduction is another sort of sorting method--bubbling sort.ThoughtThe bubble sort is also one of the simplest and most basic sorting methods, as described in the pr
Copy Code code as follows:
/**
* Bubble Sort Bubble sort
*
* Principle: Multiple loops to compare, each time the maximum number of comparisons to move to the top. Each time you loop, find the maximum value in the remaining variable, and then reduce the scope of the query. This completes the ordering of this arr
Bubble sortBubble sort is a simple sort algorithm. It repeatedly visited the sequence to sort, comparing two elements at a time, and swapping them out if they were wrong in the order. The work of the sequence of visits is repeated until no more need to be exchanged, that is, the sequence is sorted. The algorithm is nam
Bubble sort (Bubble sort), which repeatedly visits the elements to be sorted, compares adjacent two elements in turn, and swaps them if they are in the wrong order until no elements need to be exchanged again.Sorting is complete. The algorithm is named because the smaller (or larger) element will slowly "float" through
Related articlesAlgorithm (i) Time complexityPrefaceSorting is the basis of the algorithm, there are many ways to sort it out, some methods are simple to implement, but inefficient, we can call these sorts of methods an elementary sort. In this article we will learn the insertion sort and bubble
Bubble SortBubble sort (Bubble sort) is a simpler sort algorithm in the field of computer science. It repeatedly visited the sequence to sort, comparing two elements at a time, and swapping them out if they were wrong in the order
Bubble Sort (Bubblesort) is a simple sort algorithm. It repeatedly visited the sequence to sort, comparing two elements at a time, and swapping them out if they were wrong in the order. The work of the sequence of visits is repeated until no more need to be exchanged, that is, the sequence is sorted. The algorithm is n
obtained.
Code
Cout " Bubble sort: " Printline ( " Before sort: " , V ); For ( Int I = 0 ; I Int Temp = 0 ;For ( Int J = V. Size ()- 1 ; J> 0 ; J --){ If (V [J] 1 ]) {Temp = V [J];V [J] = V [J- 1 ];V [J- 1 ] = Temp;}}}Printline ( " After sort: " , V );
Analysis
Because each
1 、-------MessageFor beginners of Java students, the sort is in a strange but a basic problem. But because I have just stepped into the world of learning Java, a lot of things can not be well understood, resulting in their own can be knocked out of code or roughly to understand,But the idea of solving the problem is not very well in depth. (In fact, the beginning of learning is not necessary to be too inquisitive, until they have a certain foundation,
Copy codeThe Code is as follows: /**
* Bubble sort
*
* Principle: compare multiple cycles and move the maximum number to the top of each comparison. During each loop, find the maximum value in the remaining variables and then reduce the query range. After multiple loops, the array is sorted.
*/
Function sort_bubble ($ list)
{
$ Len = count ($ list );
If (empty ($ len) return $ list;
For ($ I = 0;
Bubble sortBubble sort is a simple sort algorithm. It repeatedly visited the sequence to sort, comparing two elements at a time, and swapping them out if they were wrong in the order. The work of the sequence of visits is repeated until no more need to be exchanged, that is, the sequence is sorted. The algorithm is nam
ObjectiveThis blog is based on the blog of the Brothers, the blog address click on it can go in, there are many good blog, my sorting algorithm is from this; some of the concepts of data architecture I will not elaborate on, Wu fan's blog is explained in detail, and I write these blog just to record their learning process, Added some of their own understanding, but also want to provide help to others. No matter what programming language you learn, when you are learning loops and arrays, you usu
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.