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. This will be a class template similar to the LinkedList code I posted on below except we will include fields int length; and Node * tailPtr; along with the original Node * headPtr.

For now just implement the same functions as in the posted below along with corresponding insertLast, removeLast and getLast methods. Also provide a getLength() method.

#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 & out

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

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

Step: 3

blur-text-image

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

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

Is it clear what happens if an employee violates the policy?

Answered: 1 week ago