Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

void normalizeBigNum(odPtr&tmpPtr;) // Task: Remove leading zeroes from a BigNum

ID: 3729181 • Letter: V

Question

void normalizeBigNum(odPtr&tmpPtr;) // Task: Remove leading zeroes from a BigNum represented by a linked list. I/ Pre: tmpPtr points to the first node of a list, or is nullptr if the 1 list is empty /I Post: all nodes at the end of the list which have a zero have been removed // Note 1: as discussed in lecture, a BigNum stores the digits of the number in reverse order, with the ones digit at the front of the list. We are deleteing leading zeroes, so they will appear at the end of the list 0 /1 Note 2: The parameter tmpPtr is passed by reference, so any changes to it will affect the pointer in the caller

Explanation / Answer

Nodeptr *normalizeBigNum(Nodeptr &tmpPtr)
{ Nodeptr *temp;
if(*tmpPtr==NULL)
return NULL;
if((*tmpPtr).bit==0)
{
temp=(*tmpPtr);
(*tmpPtr)=(*tmpPtr)->next;
free(temp);
return normalizeBigNum(tmpPtr);
}
tmpPtr->next=normalizeBigNum((*tmpPtr)->next);
return (*tmpPtr);
}
}