thank you porter
I try to use PtoC program, but I think, that it makes some mistakes or I don't understand of this program. Please I have some other codes, which i don't understand. Can someone to rewrite this pascal code to C code? Thank you very much
procedureDListInit(var L:TDList);
begin
L.Frst:=nil;
L.Lst:=nil;
L.Act:=nil;
(* PocPrv:=0; *)
end;
procedureDInsertFirst(var L:TDlist; El:TData);
var
PomUk:TUkPrv;
begin
new(PomUk);
PomUk^.Data:=El;
PomUk^.LUk:= nil; (* left pointer of new show to nil*)
PomUk^.PUk:= L.Frst; (* right of new show to actual first or nil*)
ifL.Frst<> nil
then
L.Frst^.LUk:=PomUk; (* actual first show to the left and to a new elementh*)
else(* add to empty list *)
L.Lst:=Pomuk;
L.Frst:=PomUk; (* corection of pointer of beginning *)
end;
procedureDDeleteFirst(var L:TDlist);
(* You have to check, if you canceled active element or only one element *)
var
PomUk:TUkPrv;
begin
ifL.Frst<>nil
thenbegin
PomUk:= L.Frst;
ifL.Act=L.Frst
thenL.Act:= nil; (* first was activeí, canceled of activity of list*)
ifL.Frst=L.Lst
thenbegin(* canceled first element - ceating empty list*)
L.Lst:=nil;
L.Frst:= nil
endelsebegin
L.Frst:= L.Frst^.PUk; (* actualize of beginning of the list*)
L.Frst^.LUk:= nil; (* if list isnot empty, first element to the left pointing nil*)
end;
Dispose(PomUk)
end; (* if*)
end; (* procedure*)
procedureDPostInsert(var L:TDList; El:TData);
(* Procedure must controll, if you add last element*)
var
PomUk:TUkPrv;
begin
ifL.Act<>nil
thenbegin
new(PomUk);
PomUk^.Data:= El;
PomUk^.PUk:= L.Act^.PUk; (* *)
PomUk^.LUk:= L.Act;
L.Act^.Puk:= PomUk; (*adding of left elementh to inserting elementh*)
ifL.Act=L.Lst
thenL.Lst:=PomUk(* correction of poiter at the end - new is the last*)
elsePomUk^.PUk^.LUk:=PomUk(* adding of right elementh inserting elementh *)
end; (* if*)
end; (* procedure*)
procedureDPostDelete(var L
List);
(* you have to controll, if you cancell last element *)
var
PomUk: TUkPrv;
begin
if(L.Act<> nil)
thenbegin
ifL.Act^.PUk <> nil(* can you cancel something? *)
thenbegin(* canceled elementh donot exist *)
PomUk:= L.Act^.PUk; (* pointer to conceled*)
L.Act^.PUk:= PomUk^.PUk; (* bypass of conceled *)
ifPomUk= L.Lst
thenL.Lst:=L.Act(* if the last is canceled, Act will be Lst*)
else(* common element is canceled *)
PomUk^.PUk^.LUk:= L.Act; (* element behind canceled pointing to the left to Act*)
Dispose(PomIk);
end; (*ifL.Act^.Puk <> nil*)
end; (* ifL.Act<> nil*)
end; (* procedure*)
procedureDPreDelete(var L
List);
(* you have to check if you canceled firts element*)
var
PomUk: TUkPrv;
begin
if(L.Act<> nil)
then begin
if L.Act^.LUk <> nil (* can you cancel something? *)
then begin(* canceled elementh exist *)
PomUk:= L.Act^.LUk; (* pointer to conceled*)
L.Act^.LUk:= PomUk^.LUk; (* bypass of canceled *)
ifPomUk= L.Frst
thenL.Frst:=L.Act(*if the fitst is canceled, Act will be first*)
else(*common element is canceled*)
PomUk^.LUk^.PUk:= L.Act; (* element before canceled poiting to the right to Act*)
Dispose(PomUk)
end; (*ifL.Act^.Luk <> nil*)
end; (* ifL.Act<> nil*)
end; (* procedure*)
procedure CopyDoubleList (DLOrig:TDList; var DLDupl:TDList);
var
El:TData;
begin
DInit(DLDupl);
DFirst(DLOrig);
while DActive(DLOrig) do begin
DCopy(DLOrig,El);
DSucc(DLOrig);
DInsertLast(DLDupl,El)(* inserting at the end is copying easy*)
end (* while *)
end; (* procedure *)
procedure DPreDelete(var L
List);
(* you have to chech, if you canceled first elementh *)
var
PomUk: TUkPrv;
begin
if (L.Act <> nil)
then begin
if L.Act^.LUk <> nil (* can you cancel something? *)
then begin (* canceled exist *)
PomUk:= L.Act^.LUk; (* pointer to canceled*)
L.Act^.LUk:= PomUk^.LUk;(* bypass of canceled *)
if PomUk = L.Frst
then L.Frst:=L.Act (* if first is canceled, first become active *)
else (* common element is canceled *)
PomUk^.LUk^.PUk:= L.Act; (* elementh before canceled pointing to the right to active elementh *)
Dispose(PomUk)
end (*if L.Act^.Luk <> nil *)
end (* if L.Act<> nil *)
end; (* procedure *)
//////////////////////////////////////////////
procedure QInit(var Q:TQueue);
begin
with Q do begin
QZac:=1;
QKon:=1
end (* with *)
end;
procedure QueUp (var Q:TQeue; El:TElem);
begin
Q.QPole[Q.QKon] := El;
Q.QKon:=Q.QKon + 1;
if Q.QKon > QMax
then Q.QKon := 1; (* attention of round of list *)
end;
procedure Remove (var Q:TQueue);
begin
if Q.QZac<>Q.QKon
then begin
Q.QZac:=Q.Qzac + 1;
if Q.QZac > QMax
then Q.QZac:=1; (* attention of round of array*)
end (* if *)
end;
procedure Front (Q.TQueue; var El:TElem);
(* Procedure make error if you read empty queue *)
begin
El:= Q.QPole[Q.QZac]
end;
function QEmpty(Q:TQueue): Boolean;
begin
QEmpty:= Q.Zac=Q.Kon
end;
function QFull(Q: TQueue): Boolean;
begin
QFull:= (Q.Zac=1) and (Q.Kon=QMax) or ((Q.Zac - 1) =
Q.Kon)
end;