\documentclass[11pt]{article} \usepackage{times} \usepackage{fancyheadings} \pagestyle{fancy} \usepackage{pifont} % for fancy bullets \newcommand{\headerfont}{\fontfamily{phv}\fontseries{b}\fontshape{n}% \fontsize{10}{12pt}\selectfont} \newcommand{\ttb}{\fontfamily{pcr}\fontseries{b}\fontshape{n}% \fontsize{12}{14pt}\selectfont} \newcommand{\ttsb}{\fontfamily{pcr}\fontseries{b}\fontshape{n}% \fontsize{8}{10pt}\selectfont} \newcommand{\tts}{\fontfamily{pcr}\fontseries{m}\fontshape{n}% \fontsize{8}{10pt}\selectfont} \newcommand{\largebold}{\fontfamily{ptm}\fontseries{b}\fontshape{n}% \fontsize{14}{16pt}\selectfont} \newcommand{\Largebold}{\fontfamily{ptm}\fontseries{b}\fontshape{n}% \fontsize{19}{21pt}\selectfont} \newcommand{\Largeboldital}{\fontfamily{ptm}\fontseries{b}\fontshape{it}% \fontsize{19}{21pt}\selectfont} \newcommand{\largeboldital}{\fontfamily{ptm}\fontseries{b}\fontshape{it}% \fontsize{14}{16pt}\selectfont} \newcommand{\mywidth}{6.0in} \newcommand{\st}{\rule[-.8mm]{0mm}{2mm}} \newcommand{\longst}{\rule[-3mm]{0mm}{2mm}} \newcommand{\outerbaselinesep}{12.5pt} \topmargin 0.0in \oddsidemargin 0.25in \evensidemargin 0.25in \textwidth \mywidth \textheight 8.5in \parindent 0mm %10mm \parskip 2.5mm \fboxrule=0.3mm %%%%%%%%% Headings %%%%%%%%%%%%%%%%%%%%%%% \setlength{\headwidth}{\textwidth} % This shouldn't be needed. ?? %\setlength{\headrulewidth}{0pt} % to eliminate rule under header \newcommand{\currhead}{CS 1723, Exam 2, \today} \lhead{\footnotesize \currhead} \rhead{\footnotesize Page \thepage~~of~~\pageref{'thatsall'}\hspace{0.4mm}} \lfoot{} \chead{} \cfoot{} \rfoot{} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} \sloppy \begin{center} {\largebold CS 1723, Data Structures \\ Fall Semester, 1998} \\ {\largeboldital Second Examination} \end{center} \baselineskip=\outerbaselinesep \begin{enumerate} \item \begin{enumerate} \item Consider the following arithmetic expression, similar to ones we used in a programming assignment (the \# just terminates the expression): \hspace*{1in}\verb92+3*4#9 Give the RPN form of this expression. What rule in C tells us that the {\tt *} is performed before the {\tt +}? \item There is a significant difference between the expressions \hspace*{0.75in} \verb+4*3*2#+ and \verb+4^3^2+ Describe the difference and give the corresponding RPN. \end{enumerate} \item Consider the following C code, which reads "words" from {\tt stdin} and inserts them onto a linked list. Supply the code for the missing functions {\tt printlist}, {\tt printreverse} and {\tt insert}. {\tt printlist} should just chase down the list, printing words as it encounters them. {\tt printreverse} should use {\em recursion} to print the list in reverse order (the order in which they were read). The {\tt insert} function should insert successive words into the list pointed to by {\tt p}. (I assume that {\tt insert} puts each new node at the head of the list. Hints about {\tt insert} are included below.) {\footnotesize \begin{verbatim} #include #include #include struct lnode { char *word; struct lnode *next; }; struct lnode *insert(char *w, struct lnode *p); void printlist(struct lnode *p); void printreverse(struct lnode *p); void main(void) { struct lnode *p = NULL; char w[100]; while (scanf("%s", w) != EOF) p = insert(w, p); printlist(p); printreverse(p); printf("\n"); } void printlist(struct lnode *p) { /* code for printlist here */ printf("\n"); } void printreverse (struct lnode *p) { /* code for printreverse here (no loops) */ } struct lnode *insert(char *w, struct lnode *p) { struct lnode *r; /* Set r = malloced storage for an lnode. */ /* Set r -> word = malloced storage for the input string. */ /* Copy the input string into the new storage. */ /* Give r -> next the proper value. */ /* Return the proper pointer. */ } runner% cc -o exam2_2 exam2_2.c runner% exam2_3 Now is the time for (ctrl-d entered to simulate EOF) for time the is Now (printed by printlist) Now is the time for (printed by printrecurse) \end{verbatim} } \item Consider the following C program, with parts omitted: {\footnotesize \begin{verbatim} /* Weeks program */ #include void main(void) { int i; char *weeks[] = {"none", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", NULL}; char **p; for(i = 1; i < 8; i++) printf("%s ", /* PART (a) */); printf("\n"); for(i = 1; i < 8; i++) printf("%s ", /* PART (b) */); printf("\n"); p = /* PART (c) */; while ( /* PART (d) */) printf("%s ", /* PART (e) */); printf("\n"); } runner% exam2_3 Mon Tue Wed Thu Fri Sat Sun (repeat line twice more) \end{verbatim} } \begin{enumerate} \item Supply an expression involving weeks and {\tt []} that will print correctly. \item Supply an expression involving weeks {\em without} {\tt []} that will print correctly. \item Supply an expression involving {\tt p} that will position the pointer to skip the first entry. \item Supply an expression involving {\tt p} that will terminate with the {\tt NULL} at the array's end. \item Supply an expression involving {\tt p} that will print correctly. (Notice that you must change {\tt p} here; the variable {\tt i} is not part of this loop.) \end{enumerate} \end{enumerate} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \label{'thatsall'} \end{document}