Question: rewrite the following function using recursion (C++) bool RemoveByPos (IntNodeType * & head, int pos) { assert (pos>=1 && head!=NULL); IntNodeType * p=head; //pointing to

rewrite the following function using recursion (C++)

bool RemoveByPos (IntNodeType * & head, int pos)

{

assert (pos>=1 && head!=NULL);

IntNodeType * p=head; //pointing to node to be deleted

IntNodeType * prev=NULL; //the previous node of p

int count=1; //p is pointing to count node

while (count

{

prev = p;

p = p->next;

count++;

}

if (p==NULL)

return false;

if (prev==NULL)

{

assert (pos==1);

head = p->next;

} else

{

assert (prev->next==p && p!=NULL);

prev->next = p->next;

}

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!