CS 368 Program 2: SortedList Class

What to Write

Complete the SortedList class partially defined below and available to copy from

    ~cs368-2/public/SECTION2/turnin/PROGRAM2/SortedList.h
by writing all of the member functions, as well as a main function as follows: Note that the running time of your constructor function should be constant, and the running times of your Print, Insert, and Lookup functions should be proportional to the number of strings in the list.
Also, note that only main and Print create any output. No other methods should output any information.

What to Hand In

Put your definition of the SortedList class in a file called SortedList.h. Put the code for the SortedList member functions in a file called SortedList.C. Put your main function in a file called main.C. (Note that you will need to #include "SortedList.h" in both SortedList.C and main.C, and that to create an executable you will need to use: g++ SortedList.C main.C) Hand in your code by uploading the three files.

Grading Criteria

Your grade will depend on: Note that we will be writing our own main functions to test your SortedList code, so it is very important that you use the function names and the files names specified in this assignment. Also, in your SortedList.C file, please include comments that set off each function. For example:

The SortedList Class

#include <string>
#include <fstream>

/*
 *  SortedList class
 *    
 *  A SortedList is a collection of strings in alphabetical order
 * 
 *  Operations:
 *     constructor Initialize the list to be empty.
 *     Insert      Add a given string to the list.
 *     Print       Print (to the given ostream) the strings in the list in
 *                 order, enclosed in square brackets, separated by spaces.
 *     Lookup      Return the number of times a given string occurs in the list.
 */
class SortedList {
  public:
    // constructor
    SortedList();

    // modifiers
    void Insert(string s);

    // other operations
    int Lookup(string s) const;
    void Print(ostream &output) const;

  private:
    struct ListNode {
       string data;
       ListNode *next;
    };
    
    // pointer to the first node of the list
    ListNode *head;
};


What to turn-in: SortedList.C
SortedList.h
main.C