Trees without explicit memory management

Discussion in 'C++' started by Dave, Apr 20, 2004.

  1. Dave

    Dave Guest

    Hello all,

    I am creating arbitrary trees and would like to not have to deal with memory
    management. The approach I've taken is to put each node in a std::list<>.
    Obviously, the nodes will be deallocated when the list is destroyed or when
    I call clear(). This approach works because my nodes can have simple
    pointers to parent / children / siblings since the elements in a list never
    move. Can anybody see any shortcomings in this approach or offer a superior
    alternative?

    Thanks,
    Dave
    Dave, Apr 20, 2004
    #1
    1. Advertising

  2. Dave

    bartek Guest

    "Dave" <> wrote in
    news::

    > I am creating arbitrary trees and would like to not have to deal with
    > memory management. The approach I've taken is to put each node in a
    > std::list<>. Obviously, the nodes will be deallocated when the list is
    > destroyed or when I call clear(). This approach works because my
    > nodes can have simple pointers to parent / children / siblings since
    > the elements in a list never move. Can anybody see any shortcomings
    > in this approach or offer a superior alternative?


    You could use a deque as well -- if you know you won't need to remove
    elements in the middle of the sequence. A list gives you flexibility to
    unlink middle elements w/o risk of losing references though with a little
    more memory overhead. Myself ended up using deques in a ternary search tree
    implementation.

    Cheers!
    b
    bartek, Apr 20, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J.T. Conklin
    Replies:
    1
    Views:
    437
    David Hilsee
    Aug 11, 2004
  2. Andy
    Replies:
    5
    Views:
    501
    Shezan Baig
    Jan 30, 2005
  3. Replies:
    1
    Views:
    571
    Salt_Peter
    Dec 25, 2006
  4. jacob navia

    Binary search trees (AVL trees)

    jacob navia, Jan 3, 2010, in forum: C Programming
    Replies:
    34
    Views:
    1,411
    Dann Corbit
    Jan 8, 2010
  5. Matt Oefinger
    Replies:
    0
    Views:
    212
    Matt Oefinger
    Jun 25, 2003
Loading...

Share This Page