Knowee
Questions
Features
Study Tools

Расположите пропущенные (***) строки фрагмента программы так, чтобы в нем выполнялась сортировка массива?repeatind:=true;for i:=1 to 39 doif m[i]>m[i+1] then***ind:=false;end;until ind; begin m[i+1]:=buf; buf:=m[i]; m[i]:=m[i+1];

Question

Расположите пропущенные () строки фрагмента программы так, чтобы в нем выполнялась сортировка массива?repeatind:=true;for i:=1 to 39 doif m[i]>m[i+1] thenind:=false;end;until ind; begin m[i+1]:=buf; buf:=m[i]; m[i]:=m[i+1];

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct arrangement of the missing lines in the program fragment for sorting an array would be:

var
  m: array [1..40] of integer;
  i, buf: integer;
  ind: boolean;
begin
  repeat
    ind:=true;
    for i:=1 to 39 do
      if m[i]>m[i+1] then
      begin
        buf:=m[i];
        m[i]:=m[i+1];
        m[i+1]:=buf;
        ind:=false;
      end;
  until ind;
end.

Here's a step-by-step explanation:

  1. The repeat..until loop is used to keep sorting the array until no more swaps are needed. The ind variable is used as a flag to indicate whether a swap has occurred in the current pass. If no swaps are needed, ind remains true and the loop ends.

  2. The for loop iterates over the array. For each pair of elements, if the current element is greater than the next one, they are swapped. This is done by temporarily storing the current element in buf, then replacing the current element with the next one, and finally replacing the next element with the value from buf.

  3. If a swap has occurred, ind is set to false. This means that the array is not fully sorted yet, and another pass is needed.

  4. The process repeats until a pass is made with no swaps, at which point ind remains true and the repeat..until loop ends. At this point, the array is fully sorted.

This problem has been solved

Similar Questions

Каково назначение представленного ниже фрагмента программы?p:=m[1];for i:=1 to 30 doif m[i]>p then p:=m[i];writeln(p); Поиск максимального элемента из тридцати, имеющихся в массиве Поиск в массиве первого элемента, значение которого превышает среднее Поиск в массиве из тридцати элементов значений-дубликатов Поиск минимального элемента из тридцати, имеющихся в массиве

Каково назначение представленного ниже фрагмента программы?for i:=1 to 30 dobeginwrite('Введите элемент № ',i);readln(m[i]);end;n:=0;for i:=1 to 30 doif m[i]>=0 then n:=n+1;write(n); Определение количества положительных элементов массива Определение максимального элемента массива Определение количества отрицательных элементов массива Определение суммы порядковых номеров массива

Выберите правильный формат записи одномерного массива. Type <имя типа> = Array [<сп. инд. типов>] of <тип>; Var <имя массива> : <имя типа>; Var <имя массива> = Array [<сп. инд. типов>] of <тип> Type <имя типа> : Array [<сп. инд. типов>] of <тип> Var <имя массива> : Array [<сп. инд. типов>] of <тип>;

Сопоставьте полученное после выполнения фрагмента программы значение переменной w с возможным содержимым строки, отмеченной звездочкой (*):i:=1;w:=1;Repeati:=i+1;w:=w+i;* until w>1; until w<=2; until w>4; until i>=4;

План досуговых мероприятий по изобразительному и декоративно-прикладному искусству сроком на месяц относится к …Вопрос 24Выберите один ответ:a.тематическому планированиюb.перспективному планированиюc.календарному планированиюd.оперативному планированию

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.