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

h04: Chapter 5, section 5.1 -5.4

ready? assigned due points
true Wed 10/16 12:00AM Wed 10/23 11:59PM

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

INSTEAD OF TURNING IN THIS HOMEWORK, YOU WILL TAKE A QUIZ ON GAUCHOSPACE BY THE DUE DATE.
There is NO MAKEUP for missed homework assignments.
The quiz will be made available at least two days before the due date.


Please:

  • No Staples.
  • No Paperclips.
  • No folded down corners.

Complete your reading of Chapter 5, section 5.1 -5.4 (If you don’t have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”).

    1. (2 pts) Describe a problem that can occur if you dereference a null pointer.
    2. (8 pts) Suppose you want to use a linked list where the items stored in the list are strings from the standard library string class, how would you change the node1.h header file on page 257 ?
    3. (10 pts) Write the implementation of a non-member function Node* deleteSecond(Node* head_ptr), where Node is a class defined on page 257. The function takes as input a pointer to the head of a linked list consisting of numbers. The function should remove the second item in the list. If the list had only one item, the function should delete that item. If the list was empty, then let the list remain empty. In all cases return the new head of the list
    4. (30 pts) Read the definition of the bag class on page 262 that uses a linked-list to store the items in the bag. Then explain each of the following:
    i. Why does the class overload the copy constructor?
    ii. Why does the class overload the assignment operator?
    iii. Why is it a good idea to typedef node::value_type as value_type in the bag class definition?