visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: Pascal :: Can anyone help me build a dynamic linked circular queue in pascal please or else help me fix the code ive already written?


By: progGoon U.S.A.  Date: 07/05/2003 00:00:00  English  Points: 50 Status: Answered
Quality : Excellent
All i need is a dynamic linked circular queue of up to 15 modes. It must have a boolean field called FULL to state when the queue is full. I currently wrote the following code. But I am getting an invalid qualifier error in the SHOWDATA procedure. If anyone can either help me fix my code or set me in the right direction it would really help.

PROGRAM CIRCLIST;
USES CRT;

TYPE
DataType = RECORD
chr:char;
END;

Pnode = ^node;

Node = RECORD
PNext : Pnode;
data : Datatype;
END;

CListType = RECORD
Last:PNode;
END;

VAR
CL : CListType;
PN : Pnode;
rec : datatype;

PROCEDURE CreateList (VAR CL:CListType);
BEGIN
CL.Last := NIL;
END;

PROCEDURE Append (VAR CL : CListType; PNew:PNode);
BEGIN
IF CL.Last = NIL THEN
BEGIN
PNew^.PNext := PNew;
CL.Last := PNew;
END
ELSE
BEGIN
PNew^.PNext := CL.Last^.PNext;
CL.Last^.PNext := PNew;
CL.Last := PNew;
END;
END;

FUNCTION NewNode(Rec:Datatype):PNode;
BEGIN
NewNode := New(PNode);
NewNode^.Data := Rec;
NewNode^.PNext := NIL;
END;

PROCEDURE ShowData(PCurrentNode:PNode);
BEGIN
writeln(PCurrentNode.chr);
END;

PROCEDURE Traverse (CL:CListType);
VAR
PTemp : PNode;
BEGIN
IF CL.Last <> NIL THEN
BEGIN
PTemp := CL.Last^.PNext;
REPEAT
ShowData(PTemp^);
PTemp := PTemp^.PNext;
UNTIL PTemp = CL.Last^.PNext;
END;
END;

BEGIN
clrscr;
rec.chr := 'a';
PN := NewNode(rec);
Append(Cl,PN);
rec.chr := 'b';
PN := NewNode(rec);
Append(Cl,PN);
rec.chr := 'c';
PN := NewNode(rec);
Append(Cl,PN);


Traverse (CL);
readln;

END.
By: VGR Date: 07/05/2003 23:00:00 English  Type : Answer
trivial

PROCEDURE ShowData(PCurrentNode:PNode);
BEGIN
writeln(PCurrentNode^.data.chr);
END
By: progGoon Date: 07/05/2003 23:13:00 English  Type : Comment
Thanks,

I had already figured it out but here are ure points as promised. In return would u please confirm that i am actually building a proper Dynamically linked circular queue. Thanks in advance. Also is my pointer LAST enough or are two pointers FRONT and REAR needed??
By: progGoon Date: 08/05/2003 00:05:00 English  Type : Comment
Thanks, this code looks really good.

Thanks for ure help

Do register to be able to answer

EContact
browser fav
page generated in 292.457100 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page