in c++ Suppose we implement a doubly linked list class template LinkedList with template type T. LinkedList has fields Node *headPtr, Node *tailPtr and int length, where the struct type Node has fields prev and next of type Node* along with data of type T. The prev and next pointers of each Node point to the previous and next Nodes in the list (or are respectively null in the case of the list’s head or tail node). headPtr and tailPtr should always point respectively to the first and last Nodes in the list (or be null if the list is empty) . Implement a member function   void insertAtEnd(const T & d) that allocates a new Node with data equal to d and inserts it at the end of the linked list. ONLY type the function code, not the whole class . Do not call any other member functions of the LinkedList class. Linked list class: #ifndef LINKED_LIST_H #define  LINKED_LIST_H #include "pch.h" template class Node { public:        T data;        Node * next;        Node(const T & d = T(), Node *n = nullptr) {               data = d;               next = n;        } }; template class LinkedList {        friend ostream &               operator<<(ostream & out, const LinkedList & other)        {        } private:        Node * headPtr;        // int length; public:        LinkedList () {               headPtr = nullptr;        }        LinkedList(const LinkedList & other) {               // to do        }        ~LinkedList() {               // to do        }        void insertFirst(const T & d) {               // headPtr = new Node(d, headPtr);               Node * temp = new Node(d);               temp->next = headPtr;               headPtr = temp;        }        void removeFirst() {               if (headPtr == nullptr) return;               Node * temp = headPtr;               headPtr = headPtr->next;               delete temp;        }        T getFirst() const {               if (headPtr == nullptr)                      throw logic_error("Can't get first of empty list");               return headPtr->data;        }        T getLast() const {        }        void clear() {        } }; #endif

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

in c++

Suppose we implement a doubly linked list class template LinkedList with template type T. LinkedList has fields Node *headPtr, Node *tailPtr and int length, where the struct type Node has fields prev and next of type Node* along with data of type T. The prev and next pointers of each Node point to the previous and next Nodes in the list (or are respectively null in the case of the list’s head or tail node). headPtr and tailPtr should always point respectively to the first and last Nodes in the list (or be null if the list is empty) .

Implement a member function  

void insertAtEnd(const T & d) that allocates a new Node with data equal to d and inserts it at the end of the linked list.

ONLY type the function code, not the whole class . Do not call any other member functions of the LinkedList class.

Linked list class:

#ifndef LINKED_LIST_H

#define  LINKED_LIST_H

#include "pch.h"

template <class T>

class Node {

public:

       T data;

       Node<T> * next;

       Node(const T & d = T(), Node<T> *n = nullptr) {

              data = d;

              next = n;

       }

};

template <class T>

class LinkedList {

       friend ostream &

              operator<<(ostream & out, const LinkedList & other)

       {

       }

private:

       Node<T> * headPtr;

       // int length;

public:

       LinkedList () {

              headPtr = nullptr;

       }

       LinkedList(const LinkedList<T> & other) {

              // to do

       }

       ~LinkedList() {

              // to do

       }

       void insertFirst(const T & d) {

              // headPtr = new Node<T>(d, headPtr);

              Node<T> * temp = new Node(d);

              temp->next = headPtr;

              headPtr = temp;

       }

       void removeFirst() {

              if (headPtr == nullptr) return;

              Node * temp = headPtr;

              headPtr = headPtr->next;

              delete temp;

       }

       T getFirst() const {

              if (headPtr == nullptr)

                     throw logic_error("Can't get first of empty list");

              return headPtr->data;

       }

       T getLast() const {

       }

       void clear() {

       }

};

#endif

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education