\documentclass[11pt]{article} \usepackage{times} \usepackage{fancyheadings} \pagestyle{fancy} \usepackage{pifont} % for fancy bullets \usepackage{epsfig} \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, Assignment 7: Queues Using Linked Lists, \today} \lhead{\footnotesize \currhead} \rhead{\footnotesize Page \thepage~~of~~\pageref{'thatsall'}\hspace{0.4mm}} \lfoot{} \chead{} \cfoot{} \rfoot{} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} \begin{center} {\largebold CS 1723, Data Structures \\ Fall Semester, 1998 \\ Programming Assignment 7, Due October 28, 1998 } \\ {\largeboldital Queues Using Linked Lists} \end{center} \baselineskip=\outerbaselinesep {\bf The assignment:} For this assignment you are to implement a queue of characters based on a linked list. You should mimic the linked list code for a stack that was passed out in class. See the directory on runner \verb+~wagner/pub/CS1723+ for the stack examples, files {\tt lists.text} and {\tt listss.c}. A reasonable approach is discussed at the end of this handout. It is important that you write the linked list code yourself without referring to textbooks. Your program should use the following {\tt queue.h} header file: {\small \begin{verbatim} /* * queue.h -- queue header file */ char remove(void); /* remove oldest queue item, from front */ void insert(char); /* Insert as new item, at rear */ int emptyq(); /* 1 means that the queue is empty */ int fullq(); /* 1 means no more room (which won't happen) */ \end{verbatim} } Your {\tt main()} function can be similar to the simple command interpreter in the stack routine. Your program must successfully handle an attempt to delete from an empty queue. You must use separate files for the main function, the queue header {\tt queue.h} and the code for the queue itself, {\tt queue.c}. Everything related to the actual linked list implementation should be buried inside the file {\tt queue.c}. Your program need not free storage that is no longer needed, and it also need not check for a NULL returned by {\tt malloc}. Your program should produce something like the following output: {\small \begin{verbatim} runner% queue ia Inserted: a ib Inserted: b ic Inserted: c id Inserted: d r Removed: a r Removed: b r Removed: c r Removed: d r Empty queue ix Inserted: x iy Inserted: y r Removed: x r Removed: y q runner% \end{verbatim} } \fbox{\epsfig{file=assign7.eps,angle=270}} {\bf Linked list implementation:} Everything related to the implementation must be hidden in the file {\tt queue.c}, so that you could replace linked lists in this file with a circular array and the code in the header {\tt queue.h} and in the file with the main function would remain unchanged. Your queue should look like the diagram above, with pointers named {\tt Front} and {\tt Rear}. (The diagram shows the result after inserting 'a', 'b', 'c', 'd', in that order. You need to decide how to represent an empty queue. (Perhaps both {\tt Front} and {\tt Rear} equal to {\tt NULL}.) In writing the code for {\tt insert} and {\tt remove}, it is natural to handle the case of an empty queue separately from that of a non-empty queue. (You may even need to handle a queue with one element as a separate case.) Then sometimes it is possible to combine code so that one sequence of code handles all cases, but this is only to make the code look more elegant. {\bf What to hand in:} Just a listing of the code, and a run like the one above. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \label{'thatsall'} \end{document}