Results 1 to 3 of 3

Thread: Data structures (linked list)

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Question Data structures (linked list)

    Hello everyone!
    its been awhile since i've last posted, but school is out again! Yes! Anywho!
    I've been searching and searching for some good tutorials on single and doubly linked lists, and stacks. I've found alot in C, but not C++! I was looking for the most efficent way to make a linked list, i see some people making a node class and then a list class, and they seem to make it more confusing than it really is. One time I saw a tutorial that used 3 seperate classes! So if anyone found a site that helped them understand linked lists, and would like to share, it would be greaT! thanks!

    But of course if you would like to try and teach me yourself, post up your cleanest looking linked list!
    Last edited by struntz; May 31st, 2002 at 09:36 PM.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Well, this is all in C and I wouldn't say it's the most efficient (I did it as an educational thing trying to work it out myself!).

    In C++, you can go a long way with nested classes. Are you familiar with the STL "iterator" pattern? That basically means that your implementation is irrelevant, so you can keep all the link classes private.

    I think I'm rambling....
    Attached Files Attached Files
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    There are two ways to classify linked lists.
    single-/double-linked:
    List can be single linked or double linked. SLs only contain a reference to the next item, DLs to both the next and previous item.
    Container/Inline lists:
    Most lists are container lists: they are one or more structures/classes that contain some kind of data. The linked list is most important. Nearly all examples you'll find are for such lists.
    Some classes are made as inline lists. An example is CRuntimeClass in MFC. The linked list is hard-coded into the class. You do this for classes where all instances need to be connected. The functionality of the class is most important, the linked list is less important. Working with such classes is usually dangerous as those linked lists are made only for internal use.

    Container lists consist of either only one struct/class which holds the data and the links and where you have to keep track of he start yourself, or of at least two structs/classes: one represents a node (and is often hidden inside the class) and one represents the list, containing first and last member and providing manipulation functions.

    Most C++ LLs are templated so they can store any type of data. C LLs often stored any 32-bit value (16 bit in earlier times) which could also be void pointers to memory blocks.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width