typedef
creates a new "type" in your program, so the return value and types of parameters of those functions are just your struct. It is just shorthand for using struct node
for the type.
If you were to create a new node, you could do it like this (using the type):
LLIST *node = malloc(sizeof(LLIST));
node->data = 4;
node->next = someOtherItem;
list_add(node, 1)
Also, with the function prototypes in your question, you don't really need the double pointers; since the data in your struct is just an int
, you could do something like
LLIST *list_add(int data, int position);
then the list_add
function would handle the allocation, copy the int
into the struct and add it to the linked list.
Putting it in at a certain position is as simple as changing the next
pointer in the node before it to the address of the newly allocated node, and the next
pointer in the new node to point at the next one (the one the node before that one was originally pointing at).
Keep in mind that (given the rest of your function prototypes) you will have to keep track of pointers to every node you create in order to delete them all.
I'm not sure I understand how the search function will work. This whole thing could be implemented a lot better. You shouldn't have to provide the location of a node when you create it (what if you specify a higher number than there are nodes?), etc.