\documentclass[12pt]{article} \usepackage{times} \usepackage{fancyheadings} \pagestyle{fancy} \textwidth=6.5in \oddsidemargin=0in \setlength{\headwidth}{\textwidth} % This shouldn't be needed. ?? \lhead{\footnotesize CS 1723, Data Structures, Assignment 8, \today} \rhead{\footnotesize Page \thepage~~of~~\pageref{'thatsall'}} \lfoot{} \chead{} \cfoot{} \rfoot{} \newcommand{\ttb}{\fontfamily{pcr}\fontseries{b}\fontshape{n}% \fontsize{11}{13pt}\selectfont} %Courier bold at 11pt \newcommand{\longst}{\rule[-3mm]{0mm}{2mm}} \newcommand{\st}{\rule[-.8mm]{0mm}{2mm}} \newcommand{\mywidth}{6.5in} \newcommand{\myrightmar}{0.2in} \newcommand{\myleftmar}{0.4in} \newcommand{\myparsep}{2mm} \newcommand{\mynegvertsp}{-0.35in} \newcommand{\myvspace}{-0.2in} \textwidth \mywidth \parindent 10mm \parskip 3mm \columnsep=6mm %%%10mm \topmargin=0in \textheight=9in \oddsidemargin=0in \evensidemargin=0in \begin{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % make everything sloppy \sloppy %\thispagestyle{empty} \begin{center} %{\large\bf The University of Texas at San Antonio \\ %Computer Science Program \\ %San Antonio, Texas 78249} \\ %\vspace{0.4in} {\large\bf CS 1723, Data Structures \\ Fall Semester, 1998\longst \\ Programming Assignment 8\longst } \\ {\large\it Concordance Program \\ Due November 11, 1998} \end{center} \noindent {\bf The Assignment:} On pages 139-143 (Section 6.5), your text gives the C code for a program which will print each word in an input text along with the number of times the word occurred. Using the program source itself as input, the book's program will produce output that starts as follows: {\small \begin{verbatim} 2 EOF 3 MAXWORD 5 NULL 3 a 1 add 6 addtree . . . \end{verbatim} } For this assignment you are to modify the text's program so that it produces a concordance: a list of each word in the input text, and for each word a list of the line numbers where the word occurred in the text. (This is essentially just Exercise 6-3 on page 143.) Using the same program as source, your modified program should produce output like the following. (Much of it is deleted below.) {\small \begin{verbatim} EOF: 27 77 MAXWORD: 6 25 27 NULL: 26 39 43 57 97 a: 35 64 92 add: 35 addtree: 15 29 35 36 48 50 at: 35 below: 35 break: 86 builtin: 92 c: 73 75 77 78 79 81 char: 9 15 18 19 25 36 71 74 93 95 96 ... ... (a number of lines deleted) order: 54 p: 35 36 39 40 41 42 43 45 46 48 50 51 54 55 57 58 59 60 95 96 97 98 99 print: 54 ... ... (a number of lines deleted) \end{verbatim} } \noindent {\bf Details:} \begin{enumerate} \item Relatively simple changes are needed to the source supplied in other handouts. \item You should return the current line number from the {\tt getword()} function as another parameter. You can keep track of the current line number by starting a static variable at 1 and incrementing it each time you see a \verb+'\n'+ on input. \item Inside the main struct for the tree node ({\tt tnode}) you must use a pointer to a linked list of integers, which will hold the line numbers. This will require creating another struct, and even writing another allocation function. \item The {\tt addtree()} function will have another parameter, the line number where the word occurred. {\tt addtree()} will insert this line number into the linked list associated with the node for the word. \item You should fix up the output so that for a given word it only prints a given line number once, as shown with the entry for {\tt p} above. \item You should have your program skip to a new line after printing 14 numbers (or so), again as shown with the entry for {\tt p} above. \item Print the line numbers in increasing order. There are several ways to arrange this. \item Inside the directory \verb+"~wagner/pub/CS1723"+ is the text of the assignment as {\tt "assign8.text"}, the source file as {\tt "tree.c"}, and a non-recursive version of the source as {\tt "treealt.c"}. (The file {\tt "treeprint.c"} is a similar version with single chars at nodes.) \end{enumerate} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \label{'thatsall'} \end{document}