In my delete function for a circular doubly linked list when I enter the function with two nodes and delete one node it is changing my next node and previous node to null. This only happens when I enter the function with two nodes in the linked list. I am using breakpoints in eclipse and everything seems to be working until I end the function and return the temp. After that the next and previous for ptrLocal get set to NULL. Not really sure why.
Here is the function call
struct TCB_t del = delete_from_list(&RunQ);
Here is the function
struct TCB_t delete_from_list(struct TCB_t **ptrLocal)
{
struct TCB_t temp;
if(*ptrLocal)
{
temp = **ptrLocal;
temp.next = NULL;
temp.previous =NULL;
if(*ptrLocal == (*ptrLocal)->next->next)
{
*ptrLocal = (*ptrLocal)->next;
(*ptrLocal)->next = *ptrLocal;
(*ptrLocal)->previous = *ptrLocal;
}
else if(*ptrLocal != (*ptrLocal)->next)
{
(*ptrLocal)->previous->next = (*ptrLocal)->next;
(*ptrLocal)->next->previous = (*ptrLocal)->previous;
*ptrLocal = (*ptrLocal)->next;
}
else
{
(*ptrLocal)->previous = NULL;
(*ptrLocal)->next = NULL;
*ptrLocal =NULL;
}
count--;
}
return temp;
}
After return temp ptrLocal->next and preLocal->previous are both set to null.