From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ccd10064619f1aa X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: How: Remove end of Linked List w/ tail pointer? Date: 1997/11/30 Message-ID: #1/1 X-Deja-AN: 293973311 References: <65s8gp$pdc@bgtnsc03.worldnet.att.net> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-11-30T00:00:00+00:00 List-Id: In article <65s8gp$pdc@bgtnsc03.worldnet.att.net>, byrner wrote: >Does anybody know of a way to make the TAIL pointer point to the previous node in the linked list >structure defined below without starting at the HEAD and performing a loop to search through the entire list? >Essentially, what I need to do is remove the last node from the list, but before I do this, I will have to >update the TAIL pointer so it points to the node which will be the tail of the list after I remove the last >node (the next to last node) Is this even possible without searching the entire list? I am using Ada95. The problem is you're using too low level an abstraction. A list has a pointer to the head of the list; it doesn't have a pointer to the tail. If you want that, you need some higher level abstraction, implemented in terms of a list, that maintains the tail pointer. This is how unbounded queues are implemented, ie private type Queue is record Front, Back : Node_Access; -- head and tail of list Length : Natural := 0; end record; There's nothing special you need to do to your list to get a pointer to the tail, just maintain a separate object to store that value. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271