Question: Help with finishing the core code for String Linked List : Here is the code I completed so far : StringLinkedList.h: #include #include

Help with finishing the core code for " String Linked List " :

Here is the code I completed so far :

StringLinkedList.h:

#include

#include

using namespace std;

class StringNode { // a node in a list of strings

private:

string elem; // element value

StringNode* next; // next item in the list

friend class StringLinkedList; // provide StringLinkedList access

};

class StringLinkedList { // a linked list of strings

public:

StringLinkedList(); // empty list constructor

~StringLinkedList(); // destructor

bool empty() const; // is list empty?

const string& front() const; // get front element

void addFront(const string& e); // add to front of list

void removeFront(); // remove front item list

private:

StringNode* head; // pointer to the head of list

};

StringLinkedList.cpp:

#include

#include

#include "StringLinkedList.h"

StringLinkedList::StringLinkedList() // constructor

: head(NULL) { }

StringLinkedList::~StringLinkedList() // destructor

{

while (!empty()) removeFront();

}

bool StringLinkedList::empty() const // is list empty?

{

return head == NULL;

}

const string& StringLinkedList::front() const // get front element

{

return head->elem;

}

void StringLinkedList::removeFront() { // remove front item

StringNode* old = head; // save current head

head = old->next; // skip over old head

delete old; // delete the old head

}

void StringLinkedList::addFront(const string& e) { // add to front of list

StringNode* v = new StringNode; // create new node

v->elem = e; // store data

v->next = head; // head now follows v

head = v; // v is now the head

}

I am stuck in the steps of 3 & 10 :

Help with finishing the core code for " String Linked List "

The steps for 1,2,4,5,6,7,8,9 were asking to create the code I posted above.

I tried creating the code for steps 3 & 10 "slist.cpp" :

#include

#include

#include

#include "StringLinkedList.h"

using namespace std;

int main()

{

StringNode myList[];

myList.addFront["BOS"];

myList.addFront["ATL"];

myList.addFront["MSP"];

myList.addFront["LAX"];

return 0;

}

Using the "StringLinkedList.h", what do i need to add before my main function?

The error is " ' myList ' expression must have class type " and " StringNode " is undefined.

Is there another way to write for steps 3 & 10 ?

Thank You .

3. Create a "main" function in your "slist.cpp" with an integer return type. The main must return the integer "EXIT SUCCESS" if the code executes without an exception or error. 10. Add code to the main function to create entries and add the following objects in order. Name BOS ATL MSP

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!