Отсортировать одномерный массив А[n] бинарным методом (n=30). Массив получить с помощью генератора псевдослучайных чисел — Pascal(Паскаль)

program sort2;

uses crt;

const
  max_n = 100;

type
  mass = array [1 .. max_n] of integer;

var
  a: mass;
  p, k, i, j, n: integer;

begin
  clrscr;
  randomize;
  textcolor(lightcyan);
  write('VVEDITE RAZMERNOSTY MASSIVA->>>');
  textcolor(yellow);
  readln(n);
  textcolor(lightcyan);
  write('a{');
  textcolor(yellow);
  for i := 1 to n do
  begin
    a[i] := random(100);
    write(a[i], ' ');
  end;
  textcolor(lightcyan);
  writeln('}');
  for i := 2 to n do
    for j := 1 to i - 1 do
      if a[i] < a[j] then
      begin
        p := a[i];
        for k := i - 1 downto j do
          a[k + 1] := a[k];
        a[j] := p;
      end;
  textcolor(lightcyan);
  write('a{');
  textcolor(yellow);
  for i := 1 to n do
    write(a[i], ' ');
  textcolor(lightcyan);
  writeln('}');
  readkey;

end.

Leave a Comment

5 + 4 =