Quiz 3 CS / SE 2630 Name______________________________________
10 points front and back
Given the following for problems 1 and 2:
struct Node
{
InfoType info;
Node * next;
Node ( InfoType x, Node *p = NULL ) { info = x; next = p; }
};
(2) 1. Write a recursive C++ function which subtracts X from the info field of each node in a linked list. For example, if InfoType is int and the info field of a Node contained 50 and X was 10, then this function should make that info field be 40. Note that this function requires that InfoType has an operator-
void Subtract ( Node * list, InfoType X )
{
if ( list != NULL )
{
_______________________________________________________________;
_______________________________________________________________;
}
}
(3) 2. Write a recursive function, called forwardPrint, that will print out the list in order from the first node to the last, one value to a line. [Note that we did a reverse print in class.]
(2) 3. Write a recursive C++ function, TensNeg, which returns the Ten's Negation of the number, i.e., for each digit, return (9 - digit). Thus, x = TensNeg(728394065); would set x to 271605934.
unsigned int TensNeg ( unsigned int n )
{
if ( n < 10 )
return ______________________________________________________ ;
else
return ______________________________________________________ ;
}
(3) 4. Trace to determine output when What is called as: What ( 'D', 'H', 5 );
You must show the output and properly show the activation records to get credit.
void What ( char a, char b, int c )
{
cout << a << c << endl;
if ( a < b )
What ( a + 1, b - 1, c + 1 );
cout << b << c << endl;
return;
}