Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Here is the Stringlist.h #include using namespace std; class StringList { private: struct StringNode // the Nodes of the linked list { string data; //
Here is the Stringlist.h
#includeusing namespace std; class StringList { private: struct StringNode // the Nodes of the linked list { string data; // data is a string StringNode *next; // points to next node in list }; StringNode *head; // the head pointer public: StringList(); ~StringList(); int count(); void add(string); bool remove(string); void display(); string minimum(); void sort(); };
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Here is the ListDriver.cpp
#include#include using namespace std; #include "StringList.h" int main() { //testing StringList StringList slist; string movie1 = "Star Wars"; string movie2 = "Fargo"; string movie3 = "Back to the Future"; string movie4 = "Titanic"; // Testing add/display/count cout Problem: Implement an interface that manipulates a list of strings. You will be provided with the following files on the Tracs .StringList.h containing a class declaration, set up for a linked list representation. Driver.cpp containing a main function you can use to test your implementation You will be responsible for providing the StringList.cpp file, including the implementation of the StringList member functions (described below): StringList and StringList: creates an empty list, and deallocates all the nodes in the list, respectively count: returns the total number of strings (nodes) in the list. Any duplicate strings should be counted. add(string) Adds a new node containing the string to either the beginning OR the end of the list (your choice, pick one, use the same one every time) remove(string) removes a node containing the given string from the linked list. Returns true if successful, otherwise false (if the string was not in the list) display): displays the strings in the list to the screen, one string per line. minimum(): returns the string that would come first in alphabetical (ascii) ordering. Does not change the list! sort): Here is the algorithm you must use for implementing the sort function 1. Define a StringNode* to be the head of a new list (make it the empty list). This should be a local variable (not a class member) 2. Repeat until the original list is empty: a. Find the minimum string in the original list and remove that node from the original list. Call functions you have already defined to do this. b. Insert this node into the proper position in the new list (at the end) 3. make the old head pointer (now empty) point to the new list! Input/Output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started