Deleting - Linked List

This is a discussion on Deleting - Linked List within the C Programming forums, part of the General Programming Boards category; I have created a double linked list program, where I can add and display the detail in the list. However, ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    2

    Question Deleting - Linked List

    I have created a double linked list program, where I can add and display the detail in the list.

    However, I need to delete the last item in the list without having to identify any value. Is this possible? Or do I have to search the link with the value.

    I have tried *last = NULL;
    & *last = info->prior;

    Can anyone provide the general coding?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    ... is this what you're asking for?
    Code:
    void delLast ()
    {
     node * p = last -> prior;
     p -> next = NULL;
     free (last);
     last = p;
    }
    or if last isn't global...
    Code:
    void delLast (node **last)
    {
     node *p = *last -> prior;
     p -> next = NULL;
     free (*last);
     *last = p;
    }
    As always, no promises that it'll compile... or that it's what you're looking for. The free() s could be left out I suppose, and it would have the same noticable effect, although that is a big no-no.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    2

    Cool

    Thanks, That's IT!!!
    TeeTee

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11:10 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  3. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 02:29 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21