A.linear insection sort, linear insection sort is sort that use two
array oringinal and temporary to compare and arrange the arrays a
number sample a here:a is the original and B is TEMP
pass I. A:8 6 1 9 4
B:8
the first
element in A is directly placed to B
pass 2.A:8 6 1 9 4
B.6 8
"6" is push in to the first area ,then
"8" is pushed to secondary of TEMP,
because of 6<8
pass 3.A: 8 6 1 9 4
B:1 6
8
like pass 2
, 1>6 so 1 is pushed
pass 4 A:8 6 1 9 4
B:1 6 8 9
because 9>all number
so, 9 put to the most right area.
pass 5:A:8 6 1 9 4
B.1 4 6 8 9
like pass 2 and 5,
6>4>1 so 4 is pushed between
6 and 1
sample 1:
var
K,J:integer;
A,B:array[1..5] of integer;
procedure insert;
var
L:integer;
begin
for l:= K-1 downto J do
B[L+1] := B[L];
B[J] := A[K];
end;
begin{main}
A[1]:=8; A[2]:=6; A[3]:=1; A[4]:=9; A[5]:=4;
B[1]:=A[1];{pass 1}
for K:= 2 to 5 do
begin
J:=1;
while (B[j]<=A[k]) and (J<=K-1) do
J:=J+1;
insert;
end;
for K:=1 to N do
A[K]:=B[K];
writeln(B[1],' ',B[2],' ',B[3],' ',B[4],' ',B[5]);
end.
B.merge:
merging means concat two or more array,since the arrays
are sorted,
in this merging ,A temp also required.
the sample program are attached;
next day we will talk about filehandling