Sponsored Content
Full Discussion: pascal and C
Top Forums Programming pascal and C Post 302142604 by Milla on Sunday 28th of October 2007 10:49:25 AM
Old 10-28-2007
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 LSmilieList);
(* 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 LSmilieList);
(* 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 LSmilieList);
(* 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;
 

2 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Traversing Pascal/Delphi code using GVim

Hi, I am using GVim as editor... and i am viewing code of pascal/ delphi.. my problem is its difficult to use GVim as source code browser.... normally ctags helps to traverse in vim for c/c++.. is there anything like that for pascal/ delphi to minimise this complication of each... (0 Replies)
Discussion started by: SankarV
0 Replies

2. Shell Programming and Scripting

need help in writing shell script to generate pascal's triangle

Hi :) I am learning shell scripting, I need help, I would like to have a script that produces pascal's triangle as shown in the picture http://upload.wikimedia.org/wikipedia/commons/thumb/f/f6/Pascal%27s_triangle_5.svg/250px-Pascal%27s_triangle_5.svg.png plz, help it's urgent thanks in... (1 Reply)
Discussion started by: angel1
1 Replies
All times are GMT -4. The time now is 08:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy