Linked lists

So I have a general understanding of what a linked list is and how to deal with it.
But I still need clarification regarding a few things. Could anyone answer me please: what is the preferred way of starting a new list? I mean, is it better to
create the first node, allocate space for it, set the data inside it (do all of it in main), and than pass it to the function that grows the list? Or is it better
to just create a "head" pointer of the node type, set it to NULL and pass it to
the function in which both happen: the growing of the list and the creation of
first node(as opposed to the first case when first node was created in main).
Or is it better to do everything inside the function and just call it from main
while passing to the function only values for whatever data the nodes hold?

The preferred way is to hide from the user as much as possible. For insertion you should have a method like list.add(data);. There is no need to created nodes outside that function. In facet, if the user does allocation he must do deallocation too. Otherwise everything could break if he decides to put one node in two lists.
I think its better to have a head or first pointer
Thanks hamsterman.
I took a quick look at "methods" and... wow!
I'm not there yet. We've just started on linked lists so... I'm still trying to master
the basics (like how to add and delete nodes and how to traverse a list).
Topic archived. No new replies allowed.