C++)Using the skeleton template class called LinkedList that represents a doubly linked list using raw pointers. *You may not use any STL containers in your implementations Need help with the following functions: -LinkedList(const LinkedList& other_list) Constructs a container with a copy of each of the elements in another, in the same order. -LinkedList& operator=(const LinkedList& other_list) Replaces the contents of this list with a copy of each element in another, in the same order. -void resize(std::size_t n) resizes the list so that it contains n elements. -void resize(std::size_t n, const T &fill_values) resizes the list so that it contains n elements -void remove(const T &val) Removes from the container all the elements that compare equal to val - bool operator == (const LinkedList &another) Compares this list with another for equality - bool operator != (const LinkedList &another) Compares this list with another for equality   CODE #include template class LinkedList {    struct Node; private:    struct Node {        // Constructors        T data;          Node* next = nullptr;        Node* prev = nullptr;    };    Node* head_ = nullptr;    Node* tail_ = nullptr;    std::size_t size_ = 0; public:    /** Constructs a list with a copy of each of the elements in `initial_list`, in the same order. */    LinkedList(std::initializer_list initial_list) {        this->operator=(initial_list);    }    /**Constructs a container with a copy of each of the elements in other_list, in the same order**/    LinkedList(const LinkedList& other_list){        //TODO    }    /** Replaces the contents of this list with a copy of each element in `initial_list`. */    LinkedList& operator=(std::initializer_list initial_list) {        // We should empty the list first, but for now...        this->size_ = 0;        for (auto&& val : initial_list)            this->push_back(val);        return *this;    }    /**Replaces the contents of this list with a copy of each element in other_list, in the same order.*/    LinkedList& operator=(const LinkedList& other_list){        //TODO    } /**Compares this list with another for equality.*/ bool operator == (const LinkedList &another){ // TODO }   /**Compares this list with another for equality.*/ bool operator != (const LinkedList &another){ // TODO }      /** Destroys each of the contained elements, and deallocates all memory allocated by this list. */    ~LinkedList() {        while (this->head_) {            Node* old_head = this->head_;            this->head_ = old_head->next;            delete old_head;        }    }    /**resizes the list so that it contains n elements.*/    void resize(std::size_t n){        //TODO    }    /**resizes the list so that it contains n elements*/    void resize(std::size_t n, const T &fill_values){        //TODO    }    /**Removes from the container all the elements that compare equal to val. */    void remove(const T &val){        //TODO    }    /**Returns the number of elements in the list*/    [[nodiscard]] size_t size() const{        return size_;    }    /**Returns whether the list container is empty */    [[nodiscard]] bool empty() const{        if(size_ == 0){            return true;        } else{            return false;        }    }    /** Appends a copy of `val` to this list. */    void push_back(const T& val) {        Node* new_node = new Node{val};        if (this->size_ == 0) {            this->head_ = this->tail_ = new_node;        } else {            this->tail_->next = new_node;            new_node->prev = this->tail_;            this->tail_ = new_node;        }        ++this->size_;    }    /** Prepends a copy of `val` to this list. */    void push_front(const T& val) {        Node* new_node = new Node{val};        if (this->size_ == 0) {            this->head_ = this->tail_ = new_node;        } else {            new_node->next = this->head_;            this->head_->prev = new_node;            this->head_ = new_node;        }        ++this->size_;    }    /**Deletes all values in this list.*/    void clear(){        Node *temp = head_;        while (temp){            temp = temp->next;            delete temp;        }        size_ = 0;    }    friend std::ostream& operator<<(std::ostream& out, const LinkedList& list) {        for (Node* cur = list.head_; cur; cur = cur->next) {            out << cur->data;        }        return out;    } }; int main() {    /***TESTING***/    LinkedList list{'H','E','L','L','O'};    std::cout< copyList = list;    copyList.resize(10, '!'); // HELLO!    std::cout << copyList << '\n';    copyList.remove('O'); //HELL!    std::cout << copyList << '\n';    return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

(C++)Using the skeleton template class called LinkedList that represents a doubly linked list using raw pointers.

*You may not use any STL containers in your implementations

Need help with the following functions:

-LinkedList(const LinkedList<T>& other_list)

Constructs a container with a copy of each of the elements in another, in the same order.

-LinkedList& operator=(const LinkedList& other_list)

Replaces the contents of this list with a copy of each element in another, in the same order.

-void resize(std::size_t n)

resizes the list so that it contains n elements.

-void resize(std::size_t n, const T &fill_values)

resizes the list so that it contains n elements

-void remove(const T &val)

Removes from the container all the elements that compare equal to val

- bool operator == (const LinkedList &another)

Compares this list with another for equality

- bool operator != (const LinkedList &another)

Compares this list with another for equality

 

CODE

#include <iostream>

template <typename T>

class LinkedList {

   struct Node;

private:

   struct Node {

       // Constructors

       T data;  

       Node* next = nullptr;

       Node* prev = nullptr;

   };

   Node* head_ = nullptr;

   Node* tail_ = nullptr;

   std::size_t size_ = 0;

public:

   /** Constructs a list with a copy of each of the elements in `initial_list`, in the same order. */

   LinkedList(std::initializer_list<T> initial_list) {

       this->operator=(initial_list);

   }

   /**Constructs a container with a copy of each of the elements in other_list, in the same order**/

   LinkedList(const LinkedList<T>& other_list){

       //TODO

   }

   /** Replaces the contents of this list with a copy of each element in `initial_list`. */

   LinkedList& operator=(std::initializer_list<T> initial_list) {

       // We should empty the list first, but for now...

       this->size_ = 0;

       for (auto&& val : initial_list)

           this->push_back(val);

       return *this;

   }

   /**Replaces the contents of this list with a copy of each element in other_list, in the same order.*/

   LinkedList& operator=(const LinkedList& other_list){

       //TODO

   }

/**Compares this list with another for equality.*/

bool operator == (const LinkedList &another){
// TODO

}
 

/**Compares this list with another for equality.*/

bool operator != (const LinkedList &another){
// TODO

}
 

   /** Destroys each of the contained elements, and deallocates all memory allocated by this list. */

   ~LinkedList() {

       while (this->head_) {

           Node* old_head = this->head_;

           this->head_ = old_head->next;

           delete old_head;

       }

   }

   /**resizes the list so that it contains n elements.*/

   void resize(std::size_t n){

       //TODO

   }

   /**resizes the list so that it contains n elements*/

   void resize(std::size_t n, const T &fill_values){

       //TODO

   }

   /**Removes from the container all the elements that compare equal to val. */

   void remove(const T &val){

       //TODO

   }

   /**Returns the number of elements in the list*/

   [[nodiscard]] size_t size() const{

       return size_;

   }

   /**Returns whether the list container is empty */

   [[nodiscard]] bool empty() const{

       if(size_ == 0){

           return true;

       } else{

           return false;

       }

   }

   /** Appends a copy of `val` to this list. */

   void push_back(const T& val) {

       Node* new_node = new Node{val};

       if (this->size_ == 0) {

           this->head_ = this->tail_ = new_node;

       } else {

           this->tail_->next = new_node;

           new_node->prev = this->tail_;

           this->tail_ = new_node;

       }

       ++this->size_;

   }

   /** Prepends a copy of `val` to this list. */

   void push_front(const T& val) {

       Node* new_node = new Node{val};

       if (this->size_ == 0) {

           this->head_ = this->tail_ = new_node;

       } else {

           new_node->next = this->head_;

           this->head_->prev = new_node;

           this->head_ = new_node;

       }

       ++this->size_;

   }

   /**Deletes all values in this list.*/

   void clear(){

       Node *temp = head_;

       while (temp){

           temp = temp->next;

           delete temp;

       }

       size_ = 0;

   }

   friend std::ostream& operator<<(std::ostream& out, const LinkedList& list) {

       for (Node* cur = list.head_; cur; cur = cur->next) {

           out << cur->data;

       }

       return out;

   }

};

int main() {

   /***TESTING***/

   LinkedList<char> list{'H','E','L','L','O'};

   std::cout<<list<<'\n';

   LinkedList<char> copyList = list;

   copyList.resize(10, '!'); // HELLO!

   std::cout << copyList << '\n';

   copyList.remove('O'); //HELL!

   std::cout << copyList << '\n';

   return 0;

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 9 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY