Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 *p = nullptr, Node *n= nullptr) {

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* headPtr, *tailPtr;

int length;

void copyList(Node * p) {

if (p == nullptr) return headPtr = tailPtr = nullptr;

headPtr = new Node(p->data);

for (Node *q = headPtr; p->next != nullptr; q = q->next,p= p->next) {

q->next = new Node(p->next->data, q);

}

tailPtr = p;

}

public:

LinkedList() { }

LinkedList(const LinkedList& other) {

}

~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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Postgresql 16 Administration Cookbook Solve Real World Database Administration Challenges With 180+ Practical Recipes And Best Practices

Authors: Gianni Ciolli ,Boriss Mejias ,Jimmy Angelakos ,Vibhor Kumar ,Simon Riggs

1st Edition

1835460585, 978-1835460580

More Books

Students also viewed these Databases questions