Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [70pts] Assume the following declarations and fill in the table with either the type of the given expression, or "error" if appropriate.

    struct Point {
      double x, y;
    };
    
    struct Node {
      Point data;
      Node* next;
    };
    
    Node *L;
    double a, *ptr;
    Point p;
    expression type
    *L
    L = &p
    &(L->data)
    L.next
    p->x
    *ptr = L->data.x
    *(L->next)
    &a
    L->next->data.y
    new Node
  2. [30pts] Given the struct definition

    struct Node {
      int data;
      Node* next;
    };

    and variables L and t, both of type Node*, with the values depicted in the figure below, write statement(s) that perform the following. Note: each problem is independent, meaning that changes in one part are not carried forward into the next part.

    1. Change the 8 to a 13:
    2. Change the 2 to a 6:
    3. Add the node t points to to the front of the list L — i.e. after these statements, L should point to the list 5,8,2,7.