C++ Code Consider the LinkedList class and the Node class that we saw in lecture. The LinkedList class basically represents a singly linked list. Now, for this lab, consider a doubly linked list, i.e. each node has a next and previous pointers to the next and previous node, respectively. Modify the Node class to reflect this change and implement the following methods for DoublyLinkedList class: addFirst addLast addAtIndex removeFirst removeLast removeAtIndex Note: We saw how to implement these methods for a singly linked list and the code is added as an attachment. C++ Code ***************************************************************************** ****************** ***************************************************************************** ****************** C++ Code Solution #include #include using namespace std; template class Node { public: T element; // Element contained in the node Node *next; // Pointer to the next node Node *previous; Node(T element) // Constructor { this->element = element; next = NULL; } }; template class LinkedList { public: LinkedList(); void addFirst(T element); void addLast(T element); T removeFirst() ; T removeLast(); void addAtIndex(int index, T element); T removeAtIndex(int index); void traverseList(); private: Node *head; Node *tail; int size; }; template LinkedList::LinkedList() { head = NULL; tail = NULL; size = 0; } template void LinkedList::addFirst(T element) { Node *newNode = new Node(element); newNode->next = head; if(head != NULL) { head->previous = newNode; } newNode->previous = NULL; head = newNode; size++; if (tail == NULL) tail = head; } template void LinkedList::addLast(T element) { if (tail == NULL) { head = tail = new Node(element); } else { tail->next = new Node(element); tail = tail->next; } size++; } template void LinkedList::addAtIndex(int index, T element) { if (index == 0) addFirst(element); else if (index >= size) addLast(element); else { Node *current = head; for (int i = 1; i < index; i++) current = current->next; Node *temp = current->next; current->next = new Node(element); (current->next)->next = temp; size++; } } template T LinkedList::removeFirst() { if (size == 0) exit(1); else { Node *temp = head; head = head->next; size--; T element = temp->element; delete temp; return element; } } template T LinkedList::removeLast() { if (size == 0) exit(1); else if (size == 1) { Node *temp = head; head = tail = NULL; size = 0; T element = temp->element; delete temp; return element; } else { Node *current = head; for (int i = 0; i < size - 2; i++) current = current->next; Node *temp = tail; tail = current; tail->next = NULL; size--; T element = temp->element; delete temp; return element; } } template T LinkedList::removeAtIndex(int index) { if (index < 0 || index >= size) exit(1); else if (index == 0) return removeFirst(); else if (index == size - 1) return removeLast(); else { Node *previous = head; for (int i = 1; i < index; i++) { previous = previous->next; } Node *current = previous-.