In this assignment, we want to implement a class for Linked List data structure. You will implement this class similar to the details described in the class. Your linked list must be able to work with...

1 answer below »
can get help with this c++ code pls?


In this assignment, we want to implement a class for Linked List data structure. You will implement this class similar to the details described in the class. Your linked list must be able to work with different data types, so you need to implement some of the details using templates. 1- Classes and components There are four classes that you need to implement: the linkedListType, the unorderedLinkedList, the orderedLinkedList, and the doublyLinkedList. The later three classes inherit from the linkedListType. The details about these classes are described below. You also need a struct for each node in your linked list which you should implement. Assume that all our template types are called Type. So, wherever you see Type in the following descriptions, it means it is template data type. 1-1- nodeType This is the struct for your nodes. You have already seen the implementation for this struct both in the slides and code examples. There is only one difference here and that is that this struct has also a link pointer for the case of having a doubly linked list. This struct should be a template struct with three members: the data, the next pointer, and the previous pointer. Stick with these names for your struct. Whenever you use this struct for a singly linked list, you must initialize the previous pointer for all the nodes to nullptr. Whenever you use it for a doubly linked list, you actually use the previous pointer. It is clearly not efficient to always have this pointer even for singly linked lists, but this is just for the simplicity of the assignment to only have one single struct for all nodes in both singly and doubly linked lists. 1-2- linkedListType This class is an abstract class. You define the member variables and implement some of the methods here. Later, the derived classes would implement the pure virtual methods. While testing your program, it will not be the case to actually create an object of the linkedListType class. Each declared object would be from one the other three derived classes. linkedListType # *first : nodeType # *last : nodeType # count : int + linkedListType() + linkedListType(const linkedListType&) + ~linkedListType() + initializeList() : void + destroyList() : void + isEmpty() : bool + length() : int + front() : Type + back() : Type + printList() : void + operator= (const linkedListType&) : const linkedListType & + search(const Type&) = 0 : bool + insertFirst(const Type&) = 0 : void + insertLast(const Type&) = 0 : void + deleteNode(const Type&) = 0 : void You can find the details about each of these members from your “10- Linked Lists (Part 2).pptx” file. In the following there are some extra points to mention: - front and back return the value in their data field, not a pointer to the actual node. - Equal to zero means the function will be a pure virtual function. So, these methods will be implemented in the derived classes. 1-3- unorderedLinkedList This is the class for normal singly linked lists without any orders. There are no more members here and you just need to implement the virtual methods from the base class. These methods must be implemented consistently with an unordered linked list, meaning that the search method here is different from search in ordered linked list. 1-4- orderedLinkedList This is the class for ordered singly linked lists. The nodes should be kept in ascending order according to their data field. There is one extra method here called insert, which inserts a new node at its proper place in the linked list (since it is an ordered list, each node has a specific place). The other inherited pure functions must be implemented consistently with the idea of the list being ordered. The insert method is represented as follows in the UML: + insert(const Type&) : void 1-5- doublyLinkedList This class is for unordered doubly linked lists; so, it would be similar to the unorderedLinkedList class. The only thing about it is while implementing its members, you need to also utilize the previous pointer from the nodeType struct and always set it for all nodes properly. Finally, it contains one extra method called printR which prints the list in the reverse order. For this printR function, do not use recursion, instead use the previous pointers to print the list from the end to the beginning. The printR method is represented as follows in the UML: + printR() : void 2- Main Function You do not need to provide a main function. But it is recommended that you test the functionality of your classes to make sure everything works correctly. Finally, there are a few notes: • This is a linked list assignment; you should not use arrays. • Your classes would be template classes since they need to work with nodes of different types. • Although there are only 4 functions that are pure virtual, but since the last class is a doubly linked list class, while making copies of an object, like in the copy constructor, or while copying data in assignment operator, you should also copy the previous pointers. So, you should either implement this copying of previous pointers in the original linkedListType class which results in inefficient copying of null pointers for all singly linked list classes, or make it virtual and differentiate the implementations in singly linked lists and doubly linked lists. For simplicity, it is recommended to do it in the base class.
Answered Same DayJul 08, 2021

Answer To: In this assignment, we want to implement a class for Linked List data structure. You will implement...

Ria answered on Jul 11 2021
132 Votes
#include
using namespace std;
template
struct nodeType
{
    Type data;
    struct nodeType* next;
    struct nodeType* prev;
};
template
class linkedListType
{
public:
    struct nodeType* first;
    struct nodeType* last;
    int count;
    linkedListType()
    {
        first->next = NULL;
        first->prev = NULL;
    }
    linkedListType(const linkedListType& l)
    {
        this = &l;
    }
    ~linkedListType()
    {
        delete this;
    }
    void initializeList()
    {
        first->data;
        count++;
    }
    void...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here