someone know it pls post it badly needed
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 04:11 AM.
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 08:32 AM.
I think you better post some code example... We have to see how your links look. What's their structure?
>> 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 likeshould do.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 );
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.
>> 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.