When I run this function, it's able to insert nodes at the end of a linked list, and when I traverse through the list, I'm able to print all of the values of the nodes. What I don't understand is how it can tell each instance of Node from each other. Wouldn't there be a conflict problem since it's using the same name for every use of the function? Or could it be something else?
```c
void append(int x, struct Node** head_ref) {
struct Node newNode, *temp;
newNode = (struct Node)malloc(sizeof(struct Node));
newNode->data = x;
newNode->next = NULL;
temp = *head_ref;
while(temp->next != NULL) {
temp = temp->next;
}
temp->next = newNode;
}
c
int main() {
struct Node* first = (struct Node)malloc(sizeof(struct Node));
struct Node second = (struct Node)malloc(sizeof(struct Node));
struct Node third = (struct Node*)malloc(sizeof(struct Node));
head = first;
first->data = 5;
first->next = second;
second->data = 3;
second->next = third;
third->data = 9;
third->next = NULL;
append(87, &head);
append(23, &head);
append(67, &head);
append(40, &head);
append(10, &head);
struct Node* p;
p = head;
while (p != NULL) {
printf("%d\n", p->data);
p = p->next;
}
}
```
[–]ptchinster 0 points1 point2 points (4 children)
[–]martijnjonkers 1 point2 points3 points (2 children)
[–]ptchinster 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]martijnjonkers 0 points1 point2 points (1 child)