linked list statement 4 adding a node

This is a discussion on linked list statement 4 adding a node within the C Programming forums, part of the General Programming Boards category; someone know it pls post it badly needed linked list statement 4 adding a node?...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    19

    linked list statement 4 adding a node

    someone know it pls post it badly needed

    linked list statement 4 adding a node?
    Last edited by llinocoe; 09-29-2008 at 05:11 AM.

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    Use malloc to allocate space for the list's 'next' pointer. Done. Don't forget to free the memory allocated via malloc.
    Last edited by twomers; 09-28-2008 at 09:32 AM.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    I think you better post some code example... We have to see how your links look. What's their structure?

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    >> I think you better post some code example... We have to see how your links look. What's their structure?
    Not really... it's gonna have a next pointer (it's a linked list), and you're gonna have to allocate memory to this pointer (that's malloc), then you're gonna have to free this memory (that's free). Doesn't matter how it looks. So something like
    Code:
    struct my_linked_list mll;
    
    /* ... */
    
    mll.next = (struct my_linked_list*) malloc( sizeof( struct my_linked_list ) ) ;
    mll.next->integer_value = 42;
    free( mll.next );
    should do.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    Well, you're introducing a bunch of dynamic memory stuff here. I would suspect the student is learning about linked lists in particular... which could very well be a statically sized array with forward and backward "pointers" (if doubly linked). The question was how to manipulate such links... It's a standard data organizational concept.

  6. #6
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    >> Well, you're introducing a bunch of dynamic memory stuff here.
    It's a linked list. It requires this.

    >> statically sized array
    Where's the fun in that? And I disagree with that being a linked list, though it may be linked. It's not a list, which I deem to be stretchable.

    >> linked list statement 4 adding a node
    That's what I provided. Adding suggests dynamic to me.

    Whatever.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help me debug this linked list !
    By Dark Angel in forum C Programming
    Replies: 6
    Last Post: 04-18-2008, 03:10 PM
  2. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  3. Linked List alpha insertion
    By mouse163 in forum C++ Programming
    Replies: 9
    Last Post: 02-21-2005, 02:24 PM
  4. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 06:46 PM
  5. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM

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