Exam 2 Answers


  1. c
  2. a
  3. c
  4. a
  5. d
  6. insert(), attach(), operator =, copy constructor (2 points each) (also, 2 points for _not_ listing the default constructor)

  7. double return_ith_item(sequence s, size_t i)
    {
      s.start();
      for (size_t j=1; j < i; j++)
           s.advance();
      return s.current();
    }
    
  8. (a)
    
    void set_to_x (node *head_ptr, int x)
    {
      node *p;
      for (p=head_ptr; p!=NULL; p=p->link())
           p->set_data(x);
      return;
    }
    
    
    
    
    
    (b)
    
    void set_to_x (node *head_ptr, int x)
    {
      if (head_ptr == NULL)
          return;
      else{
          head_ptr->set_data(x);
          set_to_x(head_ptr->link(), x);
          return;
      }
    }
    
  9. (we did part (b) in class...I'll do part(a) on Monday)