// A utility function to remove a node 'temp' fromt DLL. Note that the // function may change head and tail pointers, that is why pointers to // these pointers are passed. void removeNode(struct node **head_ref, struct node **tail_ref, struct node *temp) { if (*head_ref == NULL) return;
if (*head_ref == temp) *head_ref = (*head_ref)->next; if (*tail_ref == temp) *tail_ref = (*tail_ref)->prev; if (temp->next != NULL) temp->next->prev = temp->prev; if (temp->prev != NULL) temp->prev->next = temp->next;
// A utility function to remove a node 'temp' fromt DLL. Note that the
ReplyDelete// function may change head and tail pointers, that is why pointers to
// these pointers are passed.
void removeNode(struct node **head_ref, struct node **tail_ref,
struct node *temp)
{
if (*head_ref == NULL)
return;
if (*head_ref == temp)
*head_ref = (*head_ref)->next;
if (*tail_ref == temp)
*tail_ref = (*tail_ref)->prev;
if (temp->next != NULL)
temp->next->prev = temp->prev;
if (temp->prev != NULL)
temp->prev->next = temp->next;
delete(temp);
}
void appendNode(struct node **head_ref, struct node **tail_ref, char x)
ReplyDelete{
struct node *temp = new node;
temp->a = x;
temp->prev = temp->next = NULL;
if (*head_ref == NULL)
{
*head_ref = *tail_ref = temp;
return;
}
(*tail_ref)->next = temp;
temp->prev = *tail_ref;
*tail_ref = temp;
}