I have a function below that adds a node to the end of a linked list.
struct node {
char customer[100];
struct node *next;
}node;
struct node *add_name(struct node *tail, struct node *new_node)
{
struct node *temp;
if(tail==NULL) {
tail=new_node;
}
else {
temp=tail;
while (temp->next!=NULL) {
temp=temp->next;
}
temp->next=new_node; //tail points to new node
}
return tail;
}
I'm now trying to write a function that will print and then delete the first node of the linked list. However, my problem is I don't know how to do that considering I'm only looking at the end so far, not the beginning. I know I need to declare a pointer *head
to point to the first node, but how would I do that and how do I know that it's going to point to the first node? This is my first time working with linked lists, so I'm still a bit confused by them.