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. [15pts] We have a variable LIST of type Node* with the values depicted in the figure below:
    
    struct Node
    {
      int data;
      Node* next;
    };
    
    1. Suppose the following code is executed.
      
      Node* p = LIST->next;
      
      Draw a resulting diagram.
      
      
    2. Then, the following code is executed.
      
      Node* q = new Node;
      q->data = 100;
      q->next = p->next;
      
      The code execution depends on the above. Draw a resulting diagram.
      
      
    3. Then, the following code is executed.
      
      p->next = q;
      
      The code execution depends on the above. Draw a resulting diagram.
      
      
  3. [10pts] We have a variable LIST of type Node* with the values depicted in the figure below:
    
    struct Node
    {
      int data;
      Node* next;
    };
    
    Suppose that the following code is executed.
    
    Node* p = LIST->next;
    LIST->next = p->next;
    p->next = LIST;
    LIST = p;
    
    Draw a resulting diagram.
    
    
  4. [65pts] Write a program hw that works as follows:
    1. It reads in lower-case words, ending with the word "END"
    2. Then, it stores them in a linked list.
    3. Then, it reads in a single letter.
    4. Then, it prints out all words that start with that letter, in reverse order from how they were read in.
    5. Don't forget to delete the list!

    Makefile

    Download and use Makefile.
    Example runs:
    ~/$ ./hw
    Enter words followed by END:
    one two three four five six seven eight END
    What letter? t
    three
    two
    
    ~/$ ./hw
    Enter words followed by END:
    aa ab ac ad END
    What letter? a
    ad
    ac
    ab
    aa
    
    ~/$ ./hw
    Enter words followed by END:
    aa ab ac ad END
    What letter? b
    

Turn in