Question 3: use a class [8]
Suppose a class with the following definition has been implemented for us:
class StringList {
public:
StringList(); // creates an (initially empty) list of strings
~StringList(); // deallocates the list of strings
void insert(string s); // inserts a string in the list
void displaySorted(); // displays the strings in the list
// sorted alphabetically
private: // the internal list representation
struct strNode {
string str;
strNode *next, *prev;
} *front, *back;
};
|
Sample solutiona
int main(int argc, char *argv[])
{
StringList S;
for (int i = 0; i < argc; i++) {
S.insert(argv[i]);
}
S.displaySorted();
return 0;
}
|