[Issue 4420] New: insertBack() for SList

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 3 22:57:33 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4420

           Summary: insertBack() for SList
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmail.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmail.com> 2010-07-03 22:57:31 PDT ---
SList has an insertFront() but not an insertBack(). I assume that this is
because SList is a singly linked list and the last element does not have a link
to the element before it (in fact, looking at the implementation, you don't
even keep track of the last element).

However, if you keep track of just a bit more than the head node, you can
implement insertBack() as well better optimize some of its functions (like
findLastNode()). If you kept track of the last node in addition to the first
one, then you have the last node for functions like findLastNode() and you can
have back() and insertBack(). For that matter, if you made it the last two
nodes, then you could have popBack() as well. Now, that may complicate the
other list operations too much to be worthwhile, but it would expand SList's
capabilities without unduly increasing how much memory it takes like you would
with a doubly linked list.

So, it may be a bad idea when you really get down to it, but I thought that I
should at least suggest it since it would make SList more versatile.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list