The line (sort) is to permute the data arranged at random in order.
For instance, permute it as follows.
| Before it sorts it | 23 | 9 | 7 | 15 | 3 | 1 | 30 | 19 |
| After it sorts it | 1 | 3 | 7 | 9 | 15 | 19 | 23 | 30 |
In the sorting algorithm, another high-speed and stability might be necessary.
Stability is not that the order of the row of the data of the same value changes after it sorts it.
For instance, assume that the following are the results of quizzes of a certain class.
| Nobi postponing Futoshi | 0 |
| [Minamotoshizuka] | 90 |
| Great physical strength [dentakeshi] | 50 |
| Bone river [sune] husband | 50 |
| Nobi postponing Futoshi | 0 |
| Great physical strength [dentakeshi] | 50 |
| Bone river [sune] husband | 50 |
| [Minamotoshizuka] | 90 |
| Nobi postponing Futoshi | 0 |
| Bone river [sune] husband | 50 |
| Great physical strength [dentakeshi] | 50 |
| [Minamotoshizuka] | 90 |
[ Purpose of sorting ]
Though it only has to leave just as it is if it queued up originally at random
The purpose of the reason to sort it is the [zubari] retrieval purposely.
A target value must be when data is arranged where or guess.
It is possible to retrieve it more quickly than data queues up at random.
Though very various algorithms are designed to sorting
Bubble sorting especially ..that.. is often taken up plainly of the program.
However, the speed cannot be called a too excellent method because slowness.
The idea is easy.
First of all, exchange data when one eyes and the 2nd data is compared, and the second is small.
Compare the 2nd and the 3rd and exchange the following. Repeat this of data to the last minute.
Repeat the comparison and one exchange of data from eyes again when it comes to the last minute.
Data lines up if only the number of times of data repeat this.
| One eyes and the 2nd comparison | (23) | (9) | 7 | 15 | 3 | 1 | 30 | 19 |
| Exchange it because the second is small. | (9) | (23) | 7 | 15 | 3 | 1 | 30 | 19 |
| The 2nd and 3rd comparison | 9 | (23) | (7) | 15 | 3 | 1 | 30 | 19 |
| Exchange it because the third is small. | 9 | (7) | (23) | 15 | 3 | 1 | 30 | 19 |
| Thereafter, repeat this. |
[ Directions ]
SortBubble (number that is arranged of sorting, and sorted);
When operation is confirmed, it is easy to assume the type of array to be char, and to pass the character array.void SortBubble(int array[],int n) { int i,j,temp; for (i = 0;i < n - 1;i++) { for (j = 0;j < n - 1;j++) { if (array[j + 1] < array[j]) { temp = array[j];array[j] = array[j + 1];array[j + 1] = temp; } } } }
To use a double loop in bubble sorting, the calculation frequency : It becomes O(N^2).
It is low-speed as described in the start as the sorting algorithm.