Question
Implement a LinkedList class that uses a doubly-linked list as the underlying data structure. That means each node will have both a previous and a
Implement a LinkedList class that uses a doubly-linked list as the underlying data structure. That means each node will have both a previous and a next pointer along with the data.we will include fields int length; and Node * tailPtr; along with the original Node * headPtr.
Here is the .h file you should complete...
#include
#include
using namespace std;
template
class Node {
public:
T data;
Node* prev, *next;
Node(const T & d = T(), Node
data = d;
prev = p;
if (prev != nullptr) prev->next = this;
if (next != nullptr) next->prev = this;
next = n;
}
};
template
class LinkedList {
friend ostream& operator<<(ostream& out, const LinkedList& l) {
}
private:
Node
int length;
void copyList(Node
if (p == nullptr) return headPtr = tailPtr = nullptr;
headPtr = new Node
for (Node
q->next = new Node
}
tailPtr = p;
}
public:
LinkedList
LinkedList
}
~LinkedList() {
}
T& operator[] (int index) {
}
void insertFirst(const T& d ) {
}
void insertLast(const T& d) {
}
void removeFirst() {
}
void removeLast() {
}
int getLength() const {
}
bool isEmpty() {
}
void clear() {
}
void printBackwards() const {
}
void reverse() {
}
};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started