This week, more linked lists... this time doubly linked lists. However, I've done most of the hard work for you, so this lab ought to be pretty simple.
The goal this week is to read a text file, and count the number of times each letter is used in that text file. We would like to keep an ordered list, so that the letter used most often is at the top (the head) of the list, and the letters used least often are at the tail.
I've already set up a doubly linked list data structure, and provided functions to make a list, add a node to the tail of the list, print the list, free the list, and create a new node for the list. I have also added typedef's for pointers to dList structures and pointers to dNode structures. Hopefully, that makes the code easier to read. I have also created a pre-processor macro to loop through each node of the list from the head to the tail. See the printDList function for an example of using that macro.
Download lab11.zip, move it to your CS211 directory, and from that directory, run the following command:
This will create a lab10 sub-directory of the current directory. The lab11 sub-directory has several files:
Here are some hints on how to code the addLetter function...
Once you have coded the addLetter function, test you code. On the small.txt file, I got the following results:
./countLetters small.txt After reading 84 letters (and switching 74 nodes)... Letter e is used 12 times Letter a is used 11 times Letter t is used 9 times Letter w is used 6 times Letter s is used 6 times Letter h is used 5 times Letter l is used 5 times Letter r is used 5 times Letter m is used 4 times Letter i is used 3 times Letter y is used 3 times Letter n is used 3 times Letter o is used 3 times Letter d is used 2 times Letter b is used 2 times Letter f is used 1 times Letter c is used 1 times Letter v is used 1 times Letter u is used 1 times Letter g is used 1 times
The methods used in this lab are certainly not the only way to solve this problem, but it's surprising how efficient this simple implementation can be. Part of the reason for that is because the English language is surprisingly consistent in the patterns of usage of different letters, and once the computer recognizes these patterns, there are very few movements within the list. Furthermore, since the most often used letters are early in the list, search times are pretty fast.
Go to MyCourses, and open the CS-211 page, and choose the "Content" hyperlink on the left list of options. You will see a "Lab 11 Submission" icon to upload your countLetters.c file. Make this submission before the due date of Friday, December 1, at 11:59 PM. You may submit as many times as you want before the due date, but only the latest submission will be graded.
This lab is worth 10 points. You will get deductions as follows: