Board index » delphi » Double Sided Queue
Thomas Ng
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
|
Thomas Ng
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Double Sided QueueI am trying to create a double ended queue in pascal in a circular array. Can anyone please tell me the concept about. Or can anyone tell me where can deque( double queue ) : It is a list in which entrys can be added or deleted from either the first |
Clif Pe
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Double Sided QueueQuote"Thomas Ng" <t...@nel.com.sg> wrote: {The closest thing to your description in the field of linked lists is Restricting additions and deletions to the head or tail is an artificial Turbo v6.0 <clifp...@airmail.net> May 31, 1998 } Program DoubleLinkedListDemo; TYPE Procedure ExtendList(VAR hd1, t1:nPtr; c1:Char); Procedure NewHead(VAR hd2, t2:nPtr; c2:Char); Procedure Drop(VAR cell:nPtr); Procedure ShowList(hd, tl:nPtr); Writeln; Write('From tail: '); Begin head := NIL; tail := NIL; {VERY IMPORTANT} s := 'The quick '; {Add chars to head in reverse order} s := 'over the lazy dogs back.'; For n := 1 to 5 Do Drop(head); |
Frank Peel
![]() Delphi Developer |
Wed, 18 Jun 1902 08:00:00 GMT
Re:Double Sided QueueQuoteClif Penn wrote in message ews.net>... Quote
node if possible. The ends of the list are then identified by a pointer pointing to the head/tail node, rather than being NIL. This wastes a small amount of space if the nodes are normal records but makes the insertions and deletions simpler. I have suggested corrected code below. If the nodes in the list are objects with one or more virtual methods, the head and tail could be an ancestral object with no data, wasting no space. The example below can also be used to store nodes of different types, It has some other problems: don't pass the head/tail pointers as a Var FP Program DoubleLinkedListDemo; Constructor tNode.Init; Destructor tNode.Done; Procedure tNode.InsertBefore(var Node:tNode); Procedure tNode.Unlink; { Set the pointers so that another unlink will { The rest is Clif's program changed where necessary to Quote} { This is just a wrapper for InsertBefore to replace the function of the same name in the previous code } Var pN : ptChNode; Begin New(pN, Init); pN^.Ch := c; pN^.InsertBefore(List); End; Procedure NewHead(Var List:tNode; c:Char); Procedure Drop(pCell:ptNode); Procedure ShowList(var List:tNode); VAR |