C Hi I dont know how to do this question Can someone help me

#C++

Hi, I don\'t know how to do this question. Can someone help me? Thanks in advance!

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Here’s the contents of a file called example.cpp:

If you try to compile this you’ll get an error saying the header file LinkedList.h doesn’t exist. Your task for this assignment is to implement LinkedList.h so that this example program — and any other program that uses it — works correctly.

Here are the parts of the program you need to implement:

LinkedList is a class that implements a linked list. Implement this as singly-linked list, doubly-linked list, or circular list (you decide what is best).

LinkedList has a default constructor, i.e. a constructor that takes no inputs, that creates a new empty LinkedList object.

LinkedList has a destructor that deletes all the nodes on the list. This is necessary to make sure LinkedList has no memory leaks.

Assuming lst is an object of type LinkedList, then it has at least the following methods:

lst.size() returns the number of nodes currently on the linked list.

lst.add(s) adds the string s to the front of the linked list if s is not already somewhere on the list. If s is already somewhere on the list, then it does nothing.

Thus, lst.add(s) ensures that only one copy of each string occurs in lst.

lst.print() prints to cout a numbered list of all the strings in lst. The strings should be printed in the order they occur on the list. Note that because new strings are always added to the front of the list, the order of the strings should always be the same.

Please print your list neatly in the format shown in the example runs below.

The function remove_non_letters(s) takes a string s as input and returns a new string that is the same as s, except any non-letters have been removed. For example, remove_non_letters(\"M-55a3cfg.1\") returns the string \"Macfg\", and remove_non_letters(\"555-5390).returns \"\".

Note that you can add any helper code you need to implement these functions. Please don’t use code from any other sources except the C++ standard library, and implement the linked list using basic C++ (e.g. don’t just use the STL linked list!).

Solution

file1->linkedlist.h

---------

----------------------------------------------------------------------------File2--------------------

#include \"linkedlist.h\"
#include <string.h>
#include <iostream>
using namespace std;

Clist::Clist(char d)
{
head = new Node(d, NULL, NULL);
head->next = head->prev = head;
size = 1;

}
Clist::~Clist()
{

Node *tmp = this->head;
Node *temp;
while(tmp->prev)
tmp = tmp->prev;
while(tmp)
{

temp = tmp->next;
delete tmp;
tmp = temp;
}
tmp = temp = NULL;

}


void Clist::add(char d)
{
Node *n = head;
Node *p = head->prev;

Node *temp = new Node (d, p, n);
size++;

}

void Clist::print(bool dir)   
{
if (dir)
{
Node *tmp = head;
do{
cout << tmp->data;
tmp = tmp->next;
}while(tmp != head);
}else
{
Node *tmp = head;
do{
cout << tmp->data;
tmp = tmp->prev;
}while(tmp != head);
}
cout << endl;


}
void Clist::setData(char Data)
{
this->head->data = Data;
}
void Clist::setPrev(Node* Prev)
{
this->head->prev = Prev;
}
void Clist::setNext(Node* Next)
{
this->head->next = Next;
}

--------------------------------

The above representation of linkd list is circular.

#C++ Hi, I don\'t know how to do this question. Can someone help me? Thanks in advance! ////////////////////////////////////////////////////////////////////////
#C++ Hi, I don\'t know how to do this question. Can someone help me? Thanks in advance! ////////////////////////////////////////////////////////////////////////
#C++ Hi, I don\'t know how to do this question. Can someone help me? Thanks in advance! ////////////////////////////////////////////////////////////////////////

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site