CS140 Midterm Exam - October 5, 2004 - Page 3


Question 3

Behold p3.c:

#include < string.h >
#include < stdio.h >
#include "fields.h"
#include "dllist.h"

main()
{
  IS is;
  int i;
  Dllist d, tmp;
   
  d = new_dllist();

  is = new_inputstruct(NULL);

  while (get_line(is) >= 1) {
    if (is->line % 2 == 0) {
      dll_append(d, new_jval_s(strdup(is->fields[0])));
    } else {
      dll_prepend(d, new_jval_s(strdup(is->fields[0])));
    }
  }
  dll_traverse(tmp, d) {
    printf("%s\n", tmp->val.s);
  }
}

What is the output of: p3 < inputfile