//Function to delete a node at the end of the doubly linked list
void delete_end()
{
Node *temp;
temp=last;
temp->lptr->rptr=NULL;
last=temp->lptr;
free(temp);
}
____________________________________________________________________
//Function to delete a node at the beginning of the doubly linked list
void delete_beginning()
{
Node *temp;
temp=start;
temp->rptr->lptr=NULL;
start=temp->rptr;
free(temp);
}
_______________________________________________________________________
//Function to delete a node at the desired position of the doubly linked list
void delete_node_desired(int pos)
{
Node *temp=start;
int x=1;
while(x<pos && temp!=NULL)
{
temp=temp->rptr;
x++;
}
if(pos==1)
{
delete_beginning();
}
else if(temp==last)
{
delete_end();
}
else if(temp!=NULL){
temp->lptr->rptr = temp->rptr;
temp->rptr->lptr = temp->lptr;
free(temp);
}
else
{
printf(" The given position is invalid!\n");
}
}
Comentarios