Hi there. Long time no read
I have a problem with my circular list. I can add a node to the end of the list just fine, but I can't seem to add it to the beginning.
This is (sort of a pseudocode) for my adding to the end of the list
Code:
if (*head == NULL)
{
*head = new;
(*head)->next = *head;
}
else
{
last = *head;
while (last->next != *head)
last = last->next;
new->next = *head;
last->next = new;
}
I tried this for adding to beginning of the list but after adding the seccond node the program just stalls.
Code:
if (*head == NULL)
{
*head = new;
(*head)->next = *head;
}
else
{
new->next = *head;
*head = new;
}