I know that this is very very basic, but now I am starting from group up after getting frustrated with my coding practices and knowledge of standard idioms out there and elegant way of coding corner cases. The problem is to insert into tail of a linked list.
void insertattail (struct node *head, int data)
{
//First construct the node in newp
struct node *newp;
struct node *p;
newp = malloc (sizeof (struct node));
newp -> data = data;
newp -> next = NULL;
// Standard name for node pointers only used for traversal? p? q? tmp?
// if more than 1 kind of nodes?
// Then what about temp pointers for swapping etc but not exactly for traversal?
if (head == NULL) // is there more elegant way of dealing with this? any idiom?
{
head = newp;
return;
}
for (p=head; p->next != NULL; p++)
;
p->next=newp;
}
curr
for "current node pointer" to match next and previous. \$\endgroup\$