Question: circular header linked list Where is the mistake void add(int item) { node*p=new node; p->info=item; node*per=head; for(node*curr=head->next;curr!=head;curr=curr->next){ per=curr; per=per->next; curr->next=p; p->next=per; } { if(head->next==head){ p->next=head;

circular header linked list  circular header linked list Where is the mistake void add(int item)
Where is the mistake
void add(int item)
{ node*p=new node;
p->info=item;
node*per=head;
for(node*curr=head->next;curr!=head;curr=curr->next){
per=curr;
per=per->next;
curr->next=p;
p->next=per; }
{
if(head->next==head){
p->next=head;
head->next=p;}
}
}

1- void add (int item); This function inserts a new node after the first node (when the list is empty, the inserted node will be the first node)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!