1
h08
CS16 M18
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h08: Linked Lists

ready? assigned due points
true Tue 08/14 08:00AM Tue 08/21 11:00AM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the four lowest scores (if you have zeros, those are the four lowest scores).


Reading: Chapter 13.1 (up to but not including Variations of Linked Lists)

  1. (10 pts) Fill in the information in the header. The following are required to get the 10 "participation" points.
    • Filling in your name and umail address.
    • For paper submission PLEASE submit on ONE SHEET OF PAPER, double-sided if at all possible. If you must submit on two printed sheets write name on BOTH sheets and no staples, paperclips, or folded corners.
  2. (2 pts) Consider the 'head' variable in display 13.1. What is the value of head for an empty list?
  3. (6 pts) Assume you are given a pointer to the head of an existing list (named head). The nodes of the linked-list are of type struct Node (as defined in display 13.7). Write a for-loop to iterate through the list and print the data of every other element of the list (starting with the first element).
  4. (12 pts) Consider a linked list where each node is of the same type as in the previous question. Complete the definition of the function deleteNode given below, that takes as input a pointer to the head of the list, and an integer value. The function should delete all the nodes in the list whose data members have the given value. If the list is empty or if there is no node with the given value, the function should not do anything.
  5. void deleteNode(struct Node*& head, int value) {
    	
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }
    

    For all the following questions, use the definitions of the struct Node and struct LinkedList from Lab 07.

  6. (8 pts) Implement a function that returns the number of even elements in a linked list. Test your code before writing it out. Illegible code will receive 0 credit.

  7. int countEven(LinkedList* list) {
    	
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }
    
  8. (2 pts) In the implementation of a linked list, why does struct Node contain a pointer member variable of type Node*?

  9. (10 pts) Implement a function that takes a linked list and the number of elements in the list as input and returns a dynamically allocated array containing the data elements of the linked list. Test your code before writing it out.

  10. int* linkedListToArray(LinkedList* list, int len) {
    	
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }