Question: // stringList.h // Represents a list of strings. // Supports adding and removing strings, displaying and searching the list, // reversing and copying lists, and

 // stringList.h // Represents a list of strings. // Supports adding

and removing strings, displaying and searching the list, // reversing and copying

// stringList.h

// Represents a list of strings. // Supports adding and removing strings, displaying and searching the list, // reversing and copying lists, and checking if 2 lists are equal.

#include using 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(); void add(string); int findFirst(string); int findLast(string); bool remove(int); void display(); void reverse(); StringList copy(); bool equal(StringList&); };

// File Name: ListDriver.cpp // A demo driver for StringList. //

#include #include using namespace std;

#include "StringList.h"

void testEmpty() { cout

void testSizeOne() { cout

void testSizeLong() { cout

void testEqual() { cout

int main() { testEmpty(); testSizeOne(); testSizeLong(); testEqual(); }

/* ------- Test case 1, empty list ------- Display: Index of first "empty": -1 Index of last "empty": -1 Try to remove first element: false Reversed list: Copied list: ------- Test case 2, list of size 1 ------- Display: Star Wars Index of first "Star Wars": 0 Index of last "Star Wars": 0 Try to remove first element: true Reversed list: Star Wars Copied list: Star Wars ------- Test case 3, list of longer size ------- Display: Star Wars Titanic Star Wars Back to the Future Star Wars Index of first "Star Wars": 0 Index of last "Star Wars": 4 Try to remove last element: true Reversed list: Back to the Future Star Wars Titanic Star Wars Old is equal to reversed list: false Reversed list is equal to old: false Copied list: Star Wars Titanic Star Wars Back to the Future Copied list is equal to old: true ------- Test case 4, equal ------- list1 is equal to list2: true list1 is equal to list2+RLA: false list2+RLA is equal to list1: false list1+TBC is equal to list2+RLA: false

*/

Problem: Implement an interface that manipulates a list of strings. You will be provided with the following files on TRACS (Resources/PA#5 provided code): StringList.h containing a class declaration, set up for a linked list representation. ListDriver.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. add(string str) Adds a new node containing str to the end of the list. display(): displays the strings in the list to the screen, one string per line. findFirst(string str): returns the index of the first node which contains the string str (like linear search). Returns -1 if not found. Does not change the list! findLast(string str): returns the index of the last node which contains the string str. Returns -1 if not found. Does not change the list! remove(int position) removes the node at the given position from the linked list. Returns true if successful, otherwise false (if the position is not valid for the list) reverseO: reverses the order of the values in the stringList. Hint: use 3 temporary pointers. copy): returns a new StringList which is an exact duplicate of this StringList. equal (StringList &other): returns true if the other StringList is exactly the same as this one (the same size and the same values at every position. Otherwise returns false. Other must be passed by reference

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!