※スタイルシート未対応ブラウザではレイアウトを正確に再現できません。
  > | advanced by | contents  | that returns in <    
                   < [modosusu] > Color magazine monochrome light and shade   font predetermined, Gothic Ming-style type longhand   size Konaka large   standard  


  Bubble sorting   

  1. ..clause 1..: What is the line (sort)?
  2. ..clause 2..: Bubble sorting

[1] What is the line (sort)?

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
At this time, sorting to which the more it goes to the left, the more the value becomes small is called an ascending order.
Oppositely, sorting to which the more it goes to the right, the more the value becomes small is a descending order.

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
When this is permuted in a steady method, it becomes the following.
Nobi postponing Futoshi 0
Great physical strength [dentakeshi] 50
Bone river [sune] husband 50
[Minamotoshizuka] 90
The context of the great physical strength rice field and the bone river that is the same point is the same before it sorts it.
Permute the following in an unstable method.
Nobi postponing Futoshi 0
Bone river [sune] husband 50
Great physical strength [dentakeshi] 50
[Minamotoshizuka] 90
The great physical strength rice field that is the same point has changed places into the context of the bone river.
According to circumstances, it is necessary to maintain the order of the row of the person of the same point.
It is necessary to use a steady method in that case.


[ 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.

It returns to contents.


[2] Bubble sorting

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.
When bubble sorting is mounted as a program, it becomes as follows.

[   Directions   ]
SortBubble (number that is arranged of sorting, and sorted);
 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;
			}
		}
	}
}
When operation is confirmed, it is easy to assume the type of array to be char, and to pass the character array.

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.

It returns to contents.


< - It is advanced -> | in | head that returns  to returning  next |.