Bubble sorting is not only not considered the fastest method, moreover, it closes the list of the slowest methods of ordering. However, it has its advantages. So, sorting by the bubble method is the most logical and natural solution to the problem, if you need to arrange the elements in a certain order. An ordinary person manually, for example, will use it precisely - simply by intuition.
Where did such an unusual name come from?
, . . , - , - ( - ), , , .
:
- : . - , ;
- , . , , ;
- : ( ) - ;
- , , , . ;
- , ( , ) ( ) .
:
:
Sortirovka_Puzirkom;
j nachalnii_index konechii_index;
i nachalnii_index konechii_index-1;
massiv[i]>massiv[i+1] ( ), :
( );
, : , . ( : , ).
. , :
Sortirovka_Puzirkom;
sortirovka = ;
sortirovka = ;
sortirovka = ;
i nachalnii_index konechii_index-1;
massiv[i]>massiv[i+1] ( ), :
( );
sortirovka = ; (, ).
.
- . ?
- .
, . , , , .
, , , . : , .
. . Delphi ( (), C/C++ (/ ), Pascal (). .
.
8 22 4 74 44 37 1 7
1 8 22 4 74 44 37 1 7
8 22 4 74 44 1 37 7
8 22 4 74 1 44 37 7
8 22 4 1 74 44 37 7
8 22 1 4 74 44 37 7
8 1 22 4 74 44 37 7
1 8 22 4 74 44 37 7
2 1 8 22 4 74 44 7 37
1 8 22 4 74 7 44 37
1 8 22 4 7 74 44 37
1 8 22 4 7 74 44 37
1 8 4 22 7 74 44 37
1 4 8 22 7 74 44 37
3 1 4 8 22 7 74 37 44
1 4 8 22 7 37 74 44
1 4 8 22 7 37 74 44
1 4 8 7 22 37 74 44
1 4 7 8 22 37 74 44
4 1 4 7 8 22 37 44 74
1 4 7 8 22 37 44 74
1 4 7 8 22 37 44 74
1 4 7 8 22 37 44 74
5 1 4 7 8 22 37 44 74
1 4 7 8 22 37 44 74
1 4 7 8 22 37 44 74
6 1 4 7 8 22 37 44 74
1 4 7 8 22 37 44 74
7 1 4 7 8 22 37 44 74
Pascal
:
const kol_mas=10;
var massiv:array[1..kol_mas] of integer;
a, b, k: integer;
begin
writeln ('input', kol_mas, 'elements of array');
for a:=1 to kol_mas do readln( massiv[a] );
for a:=1 to kol_mas-1 do begin
for b:=a+1 to kol_mas do begin
if massiv[a]>massiv[b] then begin
k:=massiv[a]; massiv[a]:=massiv[b]; massiv[b]:=k;
end;
end;
end;
writeln ('after sort');
for a:=1 to kol_mas do writeln( massiv[a] );
end.
()
:
#include
#include
int main (int argc, char * argv [])
{
int massiv [8] = {36, 697, 73, 82, 68, 12, 183, 88}, i, ff;
for (;;) {
ff = 0;
for (i = 7; i> 0; i -) {
if (massiv [i] <massiv [i-1]) {
swap (massiv [i], massiv [i-1]);
ff ++;
}
}
if (ff == 0) break;
}
getch (); // screen delay
return 0;
}.