Midterm exam

October 22, 2002




Your name: ________________________________________



  Your id: ________________________________________



                      Your score: __________  / 100

Open textbook (but no other books), open notes. No use of computers. There are 4 problems.

Who is your TA and what is the time of your recitation? Check one of the following ...

R012   M   1000AM-1115AM     ECCH 105     Cyrus Hall
R013   M   0100PM-0215PM     ECCH 105     Damon McCoy
R014   M   0300PM-0415PM     ECCH 105     Cyrus Hall
R015   M   0500PM-0615PM     ECCH 105     Trevor Stone
R016   T   0930AM-1045AM     ECCH 105     Alan Schmidt
R017   T   1100AM-1215PM     ECCH 105     Alan Schmidt
























  1. (35 points) A doubly-linked list of the type we used in the CatalogBrowser of Assignment 3
    
    
    
    
    
    
    
    
    
    
    
    
    
    could be turned into a “circular” list by making the last node point to the first node and the first node point to the last node like this:
    
    
    
    
    
    
    
    
    
    
    
    
    
    Given a non-circular list with head pointing to its first node, write a piece of code that turns the list into a circular one.
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


  2. (20 points) For such a circular list, which of the following pieces of code would compute the number of nodes in the list? Put a check mark next to all correct answers; cross out all incorrect ones.

    A.   length = 0;
         for (current = head; 
                  current->next != head; 
                      current=current->next)
             length++;
    
    B.   length = 1;
         for (current = head; 
                  current->next != head; 
                      current=current->next)
             length++;
    
    C.   length = 0;
         for (current = head; 
                  current != head; 
                      current=current->next)
             length++;
    
    D.   length = 1;
         for (current = head; 
                  current != head; 
                      current=current->next)
             length++;
    
    E.   length = 1;
         for (current = head; 
                  current->previous != head; 
                      current=current->previous)
             length++;
    
    
    
    
    
    


  3. (20 points) Put a check mark next to all true statements; cross out all incorrect ones.

    1. Copy constructors always make “deep” copies.
    2. The default copy constructors --- the ones that get used when we don't program our own --- always make “deep” copies.
    3. When a parameter is passed “by value”, a copy of the actual parameter is being passed.
    4. When a parameter is passed “by reference”, a copy of the actual parameter is being passed.
    5. When a parameter is passed “by constant reference”, a copy of the actual parameter is being passed.
    
    
    
    
    
    
    
    


  4. (25 points) For the Catalog class of Assignment 3, write a member function deleteSecond that cuts the second node out of the list and delete-s it. Make sure your code works for lists of any length. If the list is empty or consists only of one node it needs to remain unchanged.