---
# System prepended metadata

title: Insertion Sort TB P.433
tags: [Pascal Programming D1]

---

###### tags: `Pascal Programming D1`
# Insertion Sort TB P.433

program InsertionSort;
const
     N=5;
var
   List: array[1..N] of integer;

procedure InputData;
begin
     List[1]:=5;
     List[2]:=9;
     List[3]:=7;
     List[4]:=2;
     List[5]:=3;
end;

procedure DisplayList(p:integer);
var
   count:integer;
begin
     write('Pass ',p,':');
     for count:= 1 to N do
         write(List[count]:4);
     writeln;
end;

procedure Sort;
var
   pass:integer;
   position:integer;
   element:integer;
   i, count:integer;
begin
     for pass:=1 to N-1 do
     begin
          element:=List[pass+1];
          position:=1;
          for i:= 1 to pass do
              if element>List[i]
                 then position:=i+1;
     for count:= pass downto position do
         List[count+1]:=List[count];
     List[position]:=element;
     DisplayList(pass);
     end;
end;

begin
     InputData;
     DisplayList(0);
     Sort;
end.
