README.md 931 Bytes
Newer Older
SETaratukhina's avatar
SETaratukhina committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const
    N=5;
var
    a: array [0..N] of integer;
    i, k, start_index, end_index : integer;
    wer : boolean ;
begin
    start_index:= 0;
    end_index := N - 1;
    for i:=1 to N do 
        readln(a[i]);
    wer:=  True;
    while wer = True do
     begin
      wer:= False;
       for i:=start_index to end_index do
            if (a[i] > a[i + 1]) then 
            begin
                k:= a[i];
                a[i]:= a[i + 1];
                a[i + 1] := k;
                wer:= True;
            end;
       if (not(wer))then 
            break ;
       wer:= False ;
    for i:=end_index downto start_index + 1 do
            if (a[i] < a[i - 1]) then 
            begin
                k:= a[i-1];
                a[i-1]:= a[i];
                a[i] := k;
                wer := True;
            end;
        start_index := start_index + 1;
       end;
      for i:=1 to N do 
        writeln(a[i]);
       end.