Hi everybody,
I'm writing this post because I can't understand a function, which is thought to insert a node at the beginning of a linked list.
Here we have the function:
void pre_insert(struct list ** doubleptr, float value);
Code:
void pre_insert(struct list ** doubleptr, float value) {
/*INPUT of the function:
-pointer which points to a pointer which points to a record;
-float.*/
struct list * temporary; /*I create a pointer to a record*/
temporary = *doubleptr; /*The pointer I created point to the pointer
pointed by the doublepointer of the input*/
*doubleptr = (struct list *)malloc(sizeof(struct list)); /*I create a new record,
I give his adress to the double pointer of the input*/
(*doubleptr)->value = value; /*I can't understand what happen here*/
(*doubleptr)->next_ptr = temporary;/*I can't understand what happen here*/
}
Can anyone tell me:
- if the sentences written as comments are correct;
- what happen in the last two lines.
Thank a lot!!!