Question: below is the code I have i am not sure what is going on, Can someone please help me (C++) #include #include #include //a node
below is the code I have i am not sure what is going on, Can someone please help me
(C++)

#include
//a node in a list of strings class StringNode{
private: string elem; //element value StringNode* next; /ext item in the list friend class StringLinked List; //provide StringLinkedList access
};
//a linked list of strings class StringLinked List{
public: StringLinked List(); //empty list constructor
~StringLinked List(); //destructor
bool empty() const; //is it empty ?
void addFont(const string& e); //add to front of list
void removeFront(); //remove front item list
const string& front() const; private:
StringNode* head; //pointer to the head of list
};
void Print() const; //prints all of the strings in the list (1 per line)
//test bed //add 3 strings and use this to print them. Print ()
StringLinkedList::StringLinkedList() :head(NULL) {}
StringLinkedList::~StringLinkedList() { while (!empty()) removeFront(); }
bool StringLinkedList::empty() const { return head==NULL; }
const string& StringLinkedList::front() const { return head->elem; }
//add to front of list void StringLinkedList::addFront(const string& e){ StringNode* v = new StringNode; v->elem=e; //store data v->next = head; //head now follows v head=v; //v is now the head }
void StringLinkedList::removeFront(){ StringNode* old=head; head = old->next; delete old; }
int main () { StringLinkedList list; // construct an instance list.addFront("Hello"); // Add "Hello" list.addFront("Cool"); // Add "Cool" list.addFront("bye"); // Add "bye" list.removeFront(); // Remove "bar" // List is automatically deleted now }
Problem 1: A. Implement the StringNode, StringLinkedList classes from Chapter 3. B. Implement a member function in the StringLinkedList that prints all of the strings in the list, one per line, to std::cout with the function signature: void PrintO const, C. Write a small testbed that: calls Print) on an empty list adds three strings to the list, then prints the list by calling Print(.O
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
