Thread: Deleting linked lists...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    22

    Deleting linked lists...

    Not too sure what I'm doing wrong here. Hopefully someone can shed some light on it for me

    When deleting a linked list, is it ok to simply do:

    Code:
    delete [] linked_list;
    or should you step through each item in the list and delete that?

    hope the question isn't too vague. If it is, complain and I'll fix it.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    > step through each item in the list and delete that
    Yes. From an object oriented perspective, you should have your lists's destructor delete each node it has in the list.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    22
    cool, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Singly Linked Lists: Clarification Needed
    By jedispy in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2006, 05:30 PM
  2. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  3. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 11:32 PM
  4. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM
  5. doubly linked lists
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2001, 06:25 PM