CodeSmith Community
Your Code. Your Way. Faster!

Linked list implemented stack, etc?

Latest post 05-27-2004 9:53 AM by cnahr. 1 replies.
  • 05-26-2004 2:02 PM

    • mawi
    • Not Ranked
    • Joined on 05-26-2004
    • Posts 1
    • Points 35

    Linked list implemented stack, etc?

    Hello, is there a linked list implemented stack?
     
    The one I saw used a private array for storage.
     
    A graph implementation ? I just "wrote" one because I couldnt find any. 
     
    /mawi

    Post Edited (mawi) : 5/26/2004 2:13:18 PM GMT

    • Post Points: 35
  • 05-27-2004 9:53 AM In reply to

    • cnahr
    • Top 50 Contributor
    • Joined on 06-03-2003
    • Posts 105
    • Points 2,275

    RE: Linked list implemented stack, etc?

    Not in the standard library. One problem is that linked lists require an additional link field that is stored with each element, or two fields for doubly linked lists.

    Adding such fields to the elements is usually a bad idea since it would prevent them from being stored in more than one collection at any one time. You'd have to define your own private container class that stores the actual element along with the links, but that would add an indirection to each element access that might offset the performance advantage of linked lists. (Edit: And perhaps more importantly, it would increase the load on the memory manager.)

    Besides, linked lists aren't necessarily much faster than array-backed collections in .NET anyway. Big objects are (or should be) reference types, so you don't have the situation as in C/C++ where you often use linked lists because you don't want to move big objects around.

    In .NET, you always just move small references around, using the Array.Copy method which is a fast native code operation, so the actual performance advantage of linked lists for small to medium-sized collections is questionable. You also get worse access locality for your object references which may adversely affect the CPU cache.

    Anyway, just some ruminations... I've thought about collections backed by linked lists but I'd have to see some compelling benchmarks to do them.

    Post Edited (Chris Nahr) : 5/27/2004 5:15:39 PM GMT

    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems