1. In the figure shown below, the blue arrows correspond to the links in the list. Notice that nodes which are adjacent in the list may not be adjacent in the tree.
  2. typedef struct {
      int minutes;
      int seconds;
    } time;
    
  3. // this comparison function shows one way to compare the keys. Another
    // way would be to convert both to seconds using the formula 60*minutes + seconds
    // and then comparing the seconds
    int compare_time(void *k1, void *k2) {
      time *key1 = (time *)k1;
      time *key2 = (time *)k2;
      if (key1->minutes < key2->minutes) 
        return -1;
      else if (key1->minutes > key2->minutes)
        return 1;
      else // minutes are equal--a simple subtraction of seconds 
           // will produce the correct
           // type of number, negative, 0, or positive
        return key1->seconds - key2->seconds;
    }
    
  4. int compare_time(void *k1, void *k2) {
      // the keys are stored as ints so we must cast the keys to ints
      int key1 = (int)k1;
      int key2 = (int)k2;
      return (k1 - k2);
    }
    
  5. Since the key field is a void *, we must cast the integer 1078 to a void * in order for the compiler to accept it as an argument to tree_insert
    tree_insert((void *)1078, 0, my_tree);
    
  6. It's best to use two fields to store the name. You could certainly concatenate them into one string but keeping the first and last name separate will make it easier to change the program later if the requirements for printing the strings are changed. Since I did not specify the maximum length of either the first or last name you should declare them as char *'s:
     
    typedef struct {
      char *first_name;
      char *last_name;
    } name;
    
    1. // prints the minimum key in the tree
      printf("%d\n", (int)tree_get_key(tree_min(my_tree)));
      
    2. // prints the first value that is greater than or equal to 100 in the tree.
      // find returns either a node with the key 100 or the first node with a key
      // greater than 100
      bool found;
      void *node = tree_find((void *)100, my_tree, &found);
      printf("%d\n", (int)tree_get_key(node));
      
    3. // traverses the tree's linked list in ascending order and prints the values 
      // of all the keys in the tree
      void *iter;
      
      for (iter = tree_min(my_tree); !tree_end(iter); iter = tree_next(iter)) {
        printf("%d\n", (int)tree_get_key(iter));
      }
      
  7. a. first 3
    Brad VanderZanden 16:57
    Sally Hare 16:59
    Daffy Duck 17:08
    
    b. last 2
    Mickey Mouse 20:05
    Joe Tortoise 29:08
    
    c. range 14:00 17:30
    Brad VanderZanden 16:57
    Sally Hare 16:59
    Daffy Duck 17:08
    
    d. range * 18:00
    Brad VanderZanden 16:57
    Sally Hare 16:59
    Daffy Duck 17:08
    Minnie Mouse 17:50
    
    e. range 19:00 *
    Mickey Mouse 20:05
    Joe Tortoise 29:08