D
D
dronreviews2015-03-28 18:49:34
Pascal
dronreviews, 2015-03-28 18:49:34

Selection sort output after each iteration?

const
  n = 15;

type
  mas = array[1..n]of integer;

var
  a: mas;
  i, tranz, min, l: integer;

var
  s, z: integer;

procedure SelectionSort(var A: mas; n: integer);
var
  i, j, key, count, k, s: integer;
begin
  for i := 1 to n do
  begin
    count := A[i]; key := i;
    for j := i + 1 to n do 
    begin
      
      if (A[key] > A[j]) then  key := j; end;
    if (key <> i) then
    begin
      A[i] := A[key];
      A[key] := count;
      for k := 1 to n do 
        write(a[i], ' ');
        writeln;
    end;
  end;
end;

begin
  for i := 1 to n do a[i] := n - i;
  SelectionSort(a, n);
end.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dronreviews, 2015-03-28
@dronreviews

Made

const
  n = 15;

type
  mas = array[1..n]of integer;

var
  a: mas;
  i, tranz, min, l: integer;

var
  s, z: integer;

procedure SelectionSort(var A: mas; n: integer);
var
  i, j, key, count, k, s: integer;
begin
  for i := 1 to n do
  begin
    count := A[i]; key := i;
    for j := i + 1 to n do 
    begin
      
      if (A[key] > A[j]) then  key := j; end;
    if (key <> i) then
    begin
      for k := 1 to n do 
        write(a[k], ' ');
        writeln;
      A[i] := A[key];
      A[key] := count;
      
    end;
  end;
end;

begin
  for i := 1 to n do a[i] := n - i;
  SelectionSort(a, n);
  for i := 1 to n do 
        write(a[i], ' ');
        writeln;
end.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question