//Function to Insert a node at the end of the doubly linked list
void add_node(int data)
{
Node *newptr=NULL;
newptr=(Node*)malloc(sizeof(Node));
newptr->info=data;
newptr->rptr=NULL;
if(last==NULL)
{
newptr->lptr=NULL;
start=last=newptr;
}
else
{
last->rptr=newptr;
newptr->lptr=last;
last=newptr;
}
}
_______________________________________________________________________________
//Function to Insert a node at the desired position(excluding the first and the last //position ) of the doubly linked list
void add_node_desired(int pos, int data)
{
int x=1;
Node *newptr=NULL,*move=start;
newptr=(Node*)malloc(sizeof(Node));
newptr->info=data;
newptr->rptr=NULL;
while(x<pos)
{
move=move->rptr;
x++;
}
newptr->rptr=move->rptr;
newptr->lptr=move;
move->rptr->lptr=newptr;
move->rptr=newptr;
}
Comments