== Magic Technologic Inc.==
Volume 0x0c, Algoritms 0x12, Phile #0x0a of 0x0f
|=---------------------------------------------------------------=| |=------------------=[ Дек - Структура данных ]=-----------------=| |=---------------------------------------------------------------=| |=---------------=[ Copyright (c) Flame Of Soul ]=---------------=| |=--------------=[ [E-mail]: _allbasse@yandex.ru ]=--------------=| |=---------------------------------------------------------------=| |=----------------------------=[ PAS ]=--------------------------=| |=---------------------------------------------------------------=| program _dequeue(input, output); const max=100; type dequeue = record item : array [1..max] of real; key : array [1..max] of integer; ms,me : integer; cnt : integer; end;
procedure init (var d : dequeue); begin d.ms:=0; d.me:=0; d.cnt:=0; end; { init }
function count (d : dequeue):integer; begin count:=d.cnt; end; { count }
function isempty (d : dequeue):boolean; begin if (d.cnt=0) then isempty:=true else isempty:=false; end; { isempty }
procedure del_first (var d : dequeue); begin if not isempty(d) then begin if (d.ms=max) then d.ms:=1 else inc(d.ms); dec(d.cnt); end; end; { del_first }
procedure del_last (var d : dequeue); begin if not isempty(d) then begin if (d.me=1) then d.me:=max else dec(d.me); dec(d.cnt); end; end; { del_last }
function first (d : dequeue):real; begin if not isempty(d) then first:=d.item[d.ms]; end; { first }
function last (d : dequeue):real; begin if not isempty(d) then last:=d.item[d.me]; end; { last }
procedure ins_first (var d : dequeue; val:real); begin if (d.cnt=0) then begin d.ms:=1; d.me:=1; d.cnt:=1; d.item[1]:=val; end else begin if (d.cnt<>max) then begin if (d.ms=1) then d.ms:=max else dec(d.ms); d.item[d.ms]:=val; inc(d.cnt); end; end;
end; { ins_first }
procedure ins_last (var d : dequeue; val:real); begin if (d.cnt=0) then begin d.ms:=1; d.me:=1; d.cnt:=1; d.item[1]:=val; end else begin if (d.cnt<>max) then begin if (d.me=max) then d.me:=1 else inc(d.me); d.item[d.me]:=val; inc(d.cnt); end; end; end; { ins_last }
procedure show (d : dequeue); var i,n : integer; begin if not isempty(d) then begin // writeln (d.ms:4,d.me:4,d.cnt:4); i:=d.ms; for n:=1 to count(d) do begin write(d.item[i]:4:2,' '); // write(i); if (i=max) then i:=0; inc(i); end; writeln; end; end; { show }
procedure cat (a,b : dequeue;var c:dequeue); var arr : array [1..max] of real; n,t : integer;
procedure d_to_arr (d : dequeue); var i : integer; begin i:=1; while not isempty(d) do begin arr[i]:=first(d); del_first(d); inc(i); end; end; { d_to_arr } begin d_to_arr(a); init(c); for n:=1 to count(a) do ins_last(c,arr[n]); d_to_arr(b); for n:=1 to count(b) do ins_last(c,arr[n]); end; { cat } begin
end. |=-----------------------------=[ PAS ]=---------------------------=| |=-----------------------------------------------------------------=|
|