Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10 pts] We would like you to self-test how much you retained from the lecture. Write the correct solution to the Mandatory Practice Problems. Debug your code until it runs correctly. Circle below how you wrote your code.
    1. (10 pts) I was able to write the code without referring to anything.
    2. (10 pts) I had to look at the notes, but still I was able to write the code without looking at the solution.
    3. (10 pts) I had to look at solutions to finish to code.
    4. (0 pts) I didn't do this.
    If you had to look at the solution, briefly describe what you missed but understand now.
    
    
    
    
  2. [20pts] We have a variable LIST of type Node* with the values depicted in the figure below:

    
    struct Node
    {
      int data;
      Node* next;
    };
    

    The definition of struct Node is given above too. Write statements (mostly manipulating pointers) that perform the following.

    • Each problem is independent, meaning that changes in one part are not carried forward into the next part.
    • Do not use any function. Write code directly.
    • You can introduce temporary pointer variables if necessary.
    • You cannot change data of any node. You can only change the next member of nodes.
    1. Delete 42 from the list.
       
    2. Move 42 to the front of the list. That is, the list should be 42, 87, 53, 4. You should not create or delete any node.
       
  3. [40pts] The definition of Node is given as follows:
    
    struct Node
    {
      int data;
      Node* next;
    };
    
    1. Write a recursive function that sums all the values in the list.
      
      int sum(Node* L)
      {
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      }
      
    2. Write a recursive function that prints all the values in the list in reverse order. For example, suppose the list looks as follows:

      Then, the function prints out
      4 
      53 
      42 
      87
      
      void rprint(Node* L)
      {
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      }
      

Turn in

Turn in the hardcopy in class.