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
Get step-by-step solutions from verified subject matter experts
