Richard already gave you the answer.
Please note
Quote:
node *newnode=new node();
newnode->v=a;
if(rear!=NULL)
{
rear->next=newnode;
rear->next->prev=front->next;
newnode->next=NULL;
newnode->prev=rear;
rear=newnode;
}
else
{
front->next=newnode;
front->prev=NULL;
newnode->next=NULL;
newnode->prev=front;
rear->prev=front;//<==== BUG here
rear=newnode;
}
There is a bug in the marked line: you are dereferencing a
NULL
pointer (
rear
).