Overview
Bubble sort is a simple sort algorithm. It repeatedly visits the sequence to be sorted, compares two elements at a time, and swaps them if their order is wrong. The task of visiting the series is repeated until the sequence has been sorted. The name of the algorithm comes from the fact that the smaller elements float slowly through the exchange to the beginning of the sequence.
To put it simply, it is:
The
I made a simple bubble sort using an array in my previous blog, "Bubble sorting." This blog we will implement the use of single linked list How to sort, in fact, the whole idea is the same. Sample code uploaded to: https://github.com/chenyufeng1991/BubbleSortLinkedList.
The algorithm is described as follows:
(1) Compare the adjacent two data, if the previous data is greater than the following data, will be
number of the second comparison, and the third time, You just need to compare the numbers except the last two, and so on ... In other words, without a comparison, each trip less than once, to a certain extent, reduce the amount of the algorithm.
In terms of time complexity:
1. If our data is in positive order, just take a trip to complete the sorting. The required number of comparisons and the number of records moved to a minimum, namely: cmin=n-1; Mmin=0 So, the best time complexity for
Bubble sorting algorithm is a familiar algorithm, in our study of computer professional courses, in the textbook often meet to the program, as a very simple example of the program. If you can't write the algorithm, then you've never learned a computer-related course. All right, no more gossip.
The bubble sort is to move the small element forward or the large element back. The comparison is an adjacent two e
PreviousArticleYou have already introduced two basic sorting methods: insert sorting and select sorting. Today we will introduce another sorting method, Bubble sorting.
Thoughts
Like the two sorting methods described earlier, Bubble Sorting is also one of the simplest and most basic sorting methods. The idea of Bubble Sorting is very simple, that is, to compa
ArticleDirectory
1. dialog box about pure CSS bubble implementation
2. "character method" and "border method"
Iii. Advanced applications of border Method
Iv. Description of the border Method
5. Use css3 to implement a bubble Style dialog box
Vi. Conclusion
From http://www.zhangxinxu.com by zhangxinxuAddress: http://www.zhangxinxu.com/wordpress? P = 651 1. dialog box about pure
Bubble Sorting is a simple sort. In this sort, the "Bubble Policy" is used to move the maximum element to the rightmost. During the bubble process, two adjacent elements are compared. If the left side is greater than the right side, two elements are exchanged. After such a bubble, you can ensure that the maximum is on
Bubble Sorting is really very simple. Well, if you have 15 minutes, maybe you will write it out soon. Really, I believe in you, and maybe you may think about it quite well, here, I only use this blog to record the Bubble Sorting I know.
Why is this name used for Bubble sorting?
You can think about the bubbles in the pond, floating from the bottom to the top, whet
Analysis of complexity of bubble sort time
Bubble Sorting repeatedly visits the series to be sorted and compares two elements at a time. If their order is wrong, they will be exchanged. The work of visiting a sequence is repeated until there is no need for exchange, that is, the sequence has been sorted.The operation of the Bubble Sorting Algorithm is as follows:
The basic idea of a bubble event is that an event is triggered in sequence from the most specific event target to the least specific event Target (document Object. [Html] lt; html gt; lt; head gt; lt; title gt; lt;/head gt; lt; bodyonclick quot; theClick () quot; the basic idea of a bubble event is that events are directed from the most specific event target to the least specific event Target (do
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. The work of the sequence of visits is repeated until no more need to be exchanged, that is, the sequence is sorted.The name of the algorithm is because the larger the element wil
What is bubble sort? Bubble 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. The work of the sequence of visits is repeated until no more need to be exchanged, that is, the sequence is sorted. The n
The program code is as follows:
Copy codeThe Code is as follows: // BubbleSort. cpp: defines the entry point of the console application.
//
# Include "stdafx. h"
# Include # Include Using namespace std;
# Define MAXNUM 20
Template Void Swap (T a, T B)
{
Int t =;
A = B;
B = t;
}
Template Void Bubble (T a [], int n)
{// Move the largest element in array a [0: n-1] To the right through bubbling
For (int I = 0; I {
If (a [I]> a [I + 1])
Swap (a [I], a [
Bubble sort and its optimization I. Principle and optimization principle 1. Explanation of principleBubble sort is: the first number is compared with the second number, if the condition position is not changed, then the second number is compared with the third number. If the condition is not satisfied, the position is replaced, the second number is compared with the third number, and so on, the number of trips equals the number of comparisons minus on
Bubble sort (Bubble sort)
1. The traditional bubble sort algorithm
(1) Algorithm idea
When an ascending bubble sort is performed, the next two numbers are compared from the back to the next, which is exchanged if the previous number is greater than the following number. At the end of the first iteration, the smallest e
Array-03. Bubble sort (20) time limit MS Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Xu Jianchun (Zhejiang University)The bubbling sort, which sorts n integers from small to large, works like this: compare adjacent two elements from beginning to end, and swap them if the preceding elements are larger than the following elements immediately after them. By scanning again, the last element must be the largest element. The firs
Reprint please indicate the source, thank you!Bubble Sorting algorithm idea:
Scan the record sequence from bottom to top (or up and down), and the adjacent two records Ri Ri-1 are swapped with (or Ri+1 ) if in reverse order.
Exchange Sort
Bubble sort
Quick Sort
Algorithm Description
An algorithm with a bad reputation
The sort is stable.
ArrayList impl
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.