\documentclass[12pt]{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.0in \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 1, \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 First Examination} \end{center} \baselineskip=\outerbaselinesep \begin{enumerate} \item \begin{enumerate} \item Give C declarations that will declare an array of 26 {\tt struct}s, where each {\tt struct} has a {\tt char} field and an {\tt int} field. \item Using the declarations from part (a), write a loop that will store the characters {\tt 'a'} through {\tt 'z'} in successive {\tt char} fields of the array of {\tt struct}s, and will store the integers 1 through 26 in successive {\tt int} fields of the array of {\tt struct}s. (You {\em must} use a loop to do this problem.) \end{enumerate} \item This problem is concerned with RPN. (RPN stands for ``Reverse Polish Notation.'') \begin{enumerate} \item Give the RPN that corresponds to the following ordinary arithmetic expression: \begin{verbatim} a + b * c - d # \end{verbatim} \item Consider the following input to a program (like the one written for Assignment~2) that processes items of an RPN sequence, from left to right. \begin{verbatim} 3 6 4 + 2 * + # \end{verbatim} Assume that individual digits are treated as separate operands and that the other characters (except for the final \#) are operators with two operands. Show step-by-step how a stack is used to evaluate this RPN sequence, and give the final value. (You should not write any C code for this problem.) \end{enumerate} \item Suppose we use an array to implement a circular queue of characters as follows: \begin{verbatim} #define Q_SIZE 4 /* maximum queue size */ char delete(void); /* delete (remove) from front */ void insert(char); /* insert at read */ int empty(void); /* check if empty */ int full(void); /* check if full */ char q[Q_SIZE]; /* actual queue */ int fp = 0; /* front pointer */ int rp = 0; /* rear pointer */ int qs = 0; /* size of queue */ \end{verbatim} \begin{enumerate} \item Give C code for the function {\tt insert} that inserts a {\tt char} (the parameter of {\tt insert}) at the rear of the queue. You may assume a {\tt full()} function exists. Don't forget to make this a {\em circular} queue. \item Give C code for the function {\tt empty()}. \end{enumerate} \item Consider the code \begin{verbatim} #include #include void strcpy1(char *, char *); void main(void) { char s[] = "UTSA"; char *t; t = ???; strcpy1(t, s); ... } \end{verbatim} The function {\tt strcpy1} is supposed to behave like the real {\tt strcpy} except that the latter returns a string (the result of the copy operation). \begin{enumerate} \item Draw a diagram of {\tt s} showing exactly what characters are stored in {\tt s} and at which locations of {\tt s}. \item Fill in the {\tt???} above so as to allocate exactly enough storage to hold the string. \item Write code for the {\tt strcpy1} function so that you do not use any square brackets ({\tt [} or {\tt ]}), and do not use any C string functions (such as {\tt strcpy} itself). You may use {\tt strlen} if you wish. \item For each of the following expressions, say whether they represent a string or a character, and what string or character is represented (assuming that {\tt s} is copied to {\tt t}): \begin{enumerate} \item \hspace*{0.1in}{\tt t[1]} \item \hspace*{0.1in}{\tt *t} \item \hspace*{0.1in}{\tt \&t[0]} \item \hspace*{0.1in}{\tt t+2} \item \hspace*{0.1in}{\tt *(t+2)} \end{enumerate} \end{enumerate} \end{enumerate} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \label{'thatsall'} \end{document}