Question: 1 #include 2 using namespace std; 3 4 struct Cell { 5 int value; 6 Cell* next; 7 }; 8 typedef Cell* List; 9 10

1 #include 2 using namespace std; 3 4 struct Cell { 5 int value; 6 Cell* next; 7 }; 8 typedef Cell* List; 9 10 int mm( List L ) 11 { 12 int t; 13 if ( L==nullptr ) return INT_MIN; 14 else { 15 t = mm( L->next ); 16 if (t > L->value) return t; 17 else return L->value; 18 } 19 } 20 21 int main( void ) { 22 List junk; // junk is filled up, as shown below. 23 int answer = mm(junk); 24 }

junk

Look over the code and the diagram above. The diagram shows storage for the variable junk. The main program calls the recursive function mm().

(5) Simulate execution of the function call on line 23. Starting with main(), show each stack frame that is built, with its contents and the value returned later for the function call. When you deallocate a frame, make a big X over it; dont erase it. In making your diagrams, you will have to draw pointers to cells; do this by writing ->35 to represent a pointer to the cell that has a 35 in it.

(5) What is stored in answer after return from calling mm(Junk)?

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!