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 |
Date: 07/05/2003 00:00:00 |
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 | Type : Answer |
|
| trivial PROCEDURE ShowData(PCurrentNode:PNode); BEGIN writeln(PCurrentNode^.data.chr); END |
|||
| By: progGoon | Date: 07/05/2003 23:13:00 | 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 | Type : Comment |
|
| Thanks, this code looks really good. Thanks for ure help |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








