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
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
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
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
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 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;
This article illustrates the bubbling sort of Java sort algorithm summary. Share to everyone for your reference. The specific analysis is as follows:
Bubble Sort (bubblesort) is to compare the adjacent two numbers sequentially, place the decimal number in the front, and the large numbers in the back.
Let's look at t
Bubble sort is a kind of exchange sort, the idea is to step backwards from the head of the sequence, each traversal compares the adjacent two elements, if the order is not the exchange, the sequence after the N-1 traversal is completed. Because each traversal is the largest element of the last move, similar to the bubble
two simple and representative two sort methods to compare with each other. Bubble sort and Direct select sort. I will introduce the methods of sequencing, time complexity, stability and characteristics.Basic process:The process of bubbling the sort is to compare each of the
Introduction to AlgorithmsBubble sort (Bubble sort) is a typical exchange sorting algorithm that continuously compares adjacent elements and moves large to the back, so the big one will move backwards, so call it bubbling.Algorithm description
Compares the adjacent elements. If the first one is larger (small) than the second one, swap them two;
For e
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
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.