Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <vector> #include \"Node.h\" #pragma once using namespace std; template

ID: 3684015 • Letter: #

Question

#include <vector>
#include "Node.h"

#pragma once


using namespace std;

template<class ItemType>
class SortedDoublyLinkedList {
    //DO NOT MODIFY THIS CLASS DECLARATION. FIND T-O-D-O-S to work on.
private:
    Node<ItemType> *head;
    Node<ItemType> *tail;
    int size;
public:

    SortedDoublyLinkedList();

    SortedDoublyLinkedList(Node<ItemType> *head, Node<ItemType> *tail, int size);

    SortedDoublyLinkedList(const SortedDoublyLinkedList<ItemType> &list);    // Copy constructor

    Node<ItemType> *getPointerTo(const ItemType &target) const;

    virtual ~ SortedDoublyLinkedList();    // Destructor should be virtual

    int getCurrentSize() const;

    bool isEmpty() const;

    bool add(const ItemType &newEntry);

    bool remove(const ItemType &anEntry);

    bool contains(const ItemType &anEntry) const;

    int getFrequencyOf(const ItemType &anEntry) const;

    vector<ItemType> toVector() const;

};

template<class ItemType>
SortedDoublyLinkedList<ItemType>::SortedDoublyLinkedList() : head(nullptr), tail(nullptr),
                                                             size(0) { }

template<class ItemType>
SortedDoublyLinkedList<ItemType>::SortedDoublyLinkedList(Node<ItemType> *head, Node<ItemType> *tail, int size) :
        head(head), tail(tail), size(size) { }

template<class ItemType>
SortedDoublyLinkedList<ItemType>::SortedDoublyLinkedList(const SortedDoublyLinkedList<ItemType> &list) {
   //TODO - Implement the copy constructor

}

template<class ItemType>
Node<ItemType> *SortedDoublyLinkedList<ItemType>::getPointerTo(const ItemType &target) const {
    //TODO - Return the Node pointer that contains the target(return nullptr if not found)

    return nullptr;
}

template<class ItemType>
SortedDoublyLinkedList<ItemType>::~SortedDoublyLinkedList() {
    //TODO - Implement the destructor

}

template<class ItemType>
int SortedDoublyLinkedList<ItemType>::getCurrentSize() const {
    //TODO - Return the current size

    return 0;
}

template<class ItemType>
bool SortedDoublyLinkedList<ItemType>::isEmpty() const {
    //TODO - Return True if the list is empty

    return true;
}

template<class ItemType>
bool SortedDoublyLinkedList<ItemType>::add(const ItemType &newEntry) {
   //TODO - Add an item to the sorted Doubly Linked list

    return false;
}

template<class ItemType>
bool SortedDoublyLinkedList<ItemType>::remove(const ItemType &anEntry) {
   //TODO - Remove the Item(anEntry) from the list - Return true if successful

    return false;
}

template<class ItemType>
bool SortedDoublyLinkedList<ItemType>::contains(const ItemType &anEntry) const {
   //TODO - Check if the List contains the Item(anEntry)- Return true if successful

    return false;
}

template<class ItemType>
int SortedDoublyLinkedList<ItemType>::getFrequencyOf(const ItemType &anEntry) const {
   //TODO - Return the frequency of the Item(anEntry) in the list

    return 0;
}

template<class ItemType>
vector<ItemType> SortedDoublyLinkedList<ItemType>::toVector() const {
   // DO NOT MODIFY THIS FUNCTION
    vector <ItemType> myVector;
    Node<ItemType> *cur;
    cur = this->head;
    while (cur != nullptr) {
        myVector.push_back(cur->getItem());
        cur = cur->getNext();
    }
    return myVector;
}

Explanation / Answer

#include <vector>
#include "Node.h"

#pragma once


using namespace std;

template<class ItemType>
class SortedDoublyLinkedList {


private:
    Node<ItemType> *head;
    Node<ItemType> *tail;
    int size;
public:

    SortedDoublyLinkedList();

    SortedDoublyLinkedList(Node<ItemType> *head, Node<ItemType> *tail, int size);

    SortedDoublyLinkedList(const SortedDoublyLinkedList<ItemType> &list);   

    Node<ItemType> *getPointerTo(const ItemType &target) const;

    virtual ~ SortedDoublyLinkedList();   

    int getCurrentSize() const;

    bool isEmpty() const;

    bool add(const ItemType &newEntry);

    bool remove(const ItemType &anEntry);

    bool contains(const ItemType &anEntry) const;

    int getFrequencyOf(const ItemType &anEntry) const;

    vector<ItemType> toVector() const;

};

template<class ItemType>
SortedDoublyLinkedList<ItemType>::SortedDoublyLinkedList() : head(nullptr), tail(nullptr),
                                                             size(0) { }

template<class ItemType>
SortedDoublyLinkedList<ItemType>::SortedDoublyLinkedList(Node<ItemType> *head, Node<ItemType> *tail, int size) :
        head(head), tail(tail), size(size) { }

template<class ItemType>
SortedDoublyLinkedList<ItemType>::SortedDoublyLinkedList(const SortedDoublyLinkedList<ItemType> &list) {

head(head);

tail(tail);

size(size); {}
}

template<class ItemType>
Node<ItemType> *SortedDoublyLinkedList<ItemType>::getPointerTo(const ItemType &target) const {

list *nullptr;

nullptr = target.getPointer();
        return nullptr;
}

template<class ItemType>
SortedDoublyLinkedList<ItemType>::~SortedDoublyLinkedList() {
cout << “ List has been deleted”<<end1;

}

template<class ItemType>
int SortedDoublyLinkedList<ItemType>::getCurrentSize() const {
this.size = size;

return size;

    return 0;
}

template<class ItemType>
bool SortedDoublyLinkedList<ItemType>::isEmpty() const {
if(list == isEmpty())

return true;
}

template<class ItemType>
bool SortedDoublyLinkedList<ItemType>::add(const ItemType &newEntry) {

struct node* c;

    

    if (*head_ref == NULL || (*head_ref)->Entry >= new_node -> newEntry)

    {

        new_node->next = *head_ref;

        *head_ref = new_node;

    }

    else

    {

        

        c = *head_ref;

        while (c->next!=NULL &&

               c->next->data < new_node->newEntry)

        {

            c = c->next;

        }

        new_node->next = c->next;

        c->next = new_node;

    }

}

return false;
}

template<class ItemType>
bool SortedDoublyLinkedList<ItemType>::remove(const ItemType &anEntry) {
ist.remove(anEntry);

if(removed)

cout<< “Removed successfully”;

    else return false;
}

template<class ItemType>
bool SortedDoublyLinkedList<ItemType>::contains(const ItemType &anEntry) const {

for(int i=0;i<=list.end;i++)

find(anEntry);

if(found)

return true; else   return false;
}

template<class ItemType>
int SortedDoublyLinkedList<ItemType>::getFrequencyOf(const ItemType &anEntry) const {

struct *node c = head;

int f=0;

while(c!= NULL)
{

if(c->data == anEntry) {

f++;

c= c->next;

}

return f;

    return 0;
}

template<class ItemType>
vector<ItemType> SortedDoublyLinkedList<ItemType>::toVector() const {
    vector <ItemType> myVector;
    Node<ItemType> *cur;
    cur = this->head;
    while (cur != nullptr) {
        myVector.push_back(cur->getItem());
        cur = cur->getNext();
    }
    return myVector;
}

int main()

{

SortedDoublyLinkedList list= new SortedDoublyLinkedList();

int ch;

cout << “ Enter choice:”;

cin >> ch;

switch(ch) {

case 1:   SortedDoublyLinkedList();

                break;

case 2: SortedDoublyLinkedList(Node<ItemType> *head, Node<ItemType> *tail, int size);

                break;

   case 3: SortedDoublyLinkedList(const SortedDoublyLinkedList<ItemType> &list);   

                break;

   case 4: Node<ItemType> *getPointerTo(const ItemType &target) const;

                                break;

   case 5: virtual ~ SortedDoublyLinkedList();   

                                break;

case 5: int getCurrentSize() const;

                break;

    case 6 :bool isEmpty() const;

                break;

   case 7 : bool add(const ItemType &newEntry);

                break;

case 8: bool remove(const ItemType &anEntry);

                break;

    case 9: bool contains(const ItemType &anEntry) const;

                                break;

   case 10: int getFrequencyOf(const ItemType &anEntry) const;

                break;

   case 11: vector<ItemType> toVector() const;

                                break;

}