CIS 181 Intro to Comp Sci
Class 22, April 28, 2005


ASSIGNMENT:

Read D&D, Chapter 17 (pp. 942-978), start Chapter 7 (pp.468-505)

Exercise Due Tuesday, May 3

In class we discussed the ConcordNode and ConcordList classes. I provided definitions and implementations of these classes, along with a driver program to see how the classes worked (including a print function associated with ConcordList that simply printed out the word field of each list element).

For Tuesday, provide the print member function (of ConcordList) for the assignment that prints the word/frequency pairs for each element in the list in tabular form (this is the one that will produce the alphabetical listing for the project). You may assume that the list is stored alphabetically. Alter the driver program provided so that it reads in both a word and a frequency when inserting into the list. Provide an option in the instructions that will allow the user to print out the word/frequency pairs in tabular format. Call the driver program and insert a number of words with their frequencies, and then choose the option that will call your new printing function to show that it works.

Exercise Tuesday, May 3

Provide the frequency-sorted print function that prints out the list elements "sorted" so that those words with the highest frequency are presented first. Please see the bottom of page 2 of the assignment where it provides some hints on how to do this. In particular, please note that it does not require sorting the list -- you just need to walk through the list several times in order to print out the elements.

Alter the driver program so that printing out the list ordered by frequency is an option in the instructions. Show that your function works by inserting a number of words with frequencies in a list, and then printing out the list sorted both alphabetically (or ordered the way the entries are in the list) and using your new member function to print them sorted by frequencies.

Exercise Due Thursday, May 5

The functionality implemented in the files that I provide include inserting a new node into the list at either the front or at the back of the list. For this assignment, you write a member function that will insert a node into a list at the spot where it belongs according to the alphabetical order of the list. This will involve (1) going through the list and determining what node the new node needs to be inserted AFTER (this will require walking two pointers down the list -- one following the other by one node -- the trailing pointer is the place where the new node is to be inserted after if the node that the leading pointer is pointing to is alphabetically beyond the word you are trying to insert); (2) actually doing the insertion of the new node. Always be careful to handle the boundary conditions -- e.g., when the new node is being inserted as the first node or last node in the list.

Again alter the driver program so that calls can be made to your new function, and show that the new function works as expected


TODAY'S TOPICS
 
  1. Linked Lists --
    self-referential classes
    friends
    dynamic memory allocation
    constructors and destructors

    printing a linked list

    See the files
    http://www.cis.udel.edu/~mccoy/courses/cisc181-05s/programming-projects/clistnd.h
    http://www.cis.udel.edu/~mccoy/courses/cisc181-05s/programming-projects/clistnd.cc
    http://www.cis.udel.edu/~mccoy/courses/cisc181-05s/programming-projects/clist.h
    http://www.cis.udel.edu/~mccoy/courses/cisc181-05s/programming-projects/clist.cc
    http://www.cis.udel.edu/~mccoy/courses/cisc181-05s/programming-projects/clist-driver.cc