Question: C++ fill out the empty functions within the DoublyLinkedList.cpp file //DoublyLinkedList.cpp file #include stdafx.h #include DoublyLinkedList.h #include #include using namespace std; DoublyLinkedList::DoublyLinkedList() { } DoublyLinkedList::DoublyLinkedList(int

C++ fill out the empty functions within the DoublyLinkedList.cpp file

//DoublyLinkedList.cpp file

#include "stdafx.h"

#include "DoublyLinkedList.h"

#include

#include

using namespace std;

DoublyLinkedList::DoublyLinkedList()

{

}

DoublyLinkedList::DoublyLinkedList(int val) //initialize

{

}

DoublyLinkedList::~DoublyLinkedList()

{

}

void DoublyLinkedList::insert_back(int val)

{

Node* n = new Node(val);

}

void DoublyLinkedList::insert_front(int val)

{

Node* n = new Node(val);

if (head == nullptr)

tail = n;

n->next = head; head = n;

if (n->next != nullptr)

n->next->prev = head;

}

void DoublyLinkedList::insert_at(int val, int idx)

{

}

Node& DoublyLinkedList::find(int val)

{

Node* n = new Node(val);

}

void DoublyLinkedList::delete_at(int idx)

{

}

Node& DoublyLinkedList::get_head() { return *head; }

Node& DoublyLinkedList::get_tail() { return *tail; }

Node const& DoublyLinkedList::get_head() const { return *head; }

Node const& DoublyLinkedList::get_tail() const { return *tail; }

ostream& operator<<(ostream &os, DoublyLinkedList const& ll) {

os << "Doubly Linked List" << endl;

os << "Head: " << &(ll.get_head()) << "\t Tail: " << &(ll.get_tail()) << endl;

Node const* curr = &(ll.get_head());

os << "Nodes (accessible from head to tail):" << endl << endl;

os << setw(16) << setfill(' ') << ' ' << ' ' << center("prev", 15) << ' ' << center("data", 15) << ' ' << center("next", 15) << endl;

while (curr != nullptr) {

ostringstream oss; oss << (curr->prev); string prev = oss.str(); oss.str(""); oss << (curr->next); string next = oss.str(); oss.str(""); oss << (curr->data); string data = oss.str(); oss.str(""); oss << curr; string address = oss.str();

os << setw(16) << setfill(' ') << ' ' << '.' << setw(16) << setfill('-') << '.' << setw(16) << '.' << setw(16) << '.' << endl;

os << setw(16) << setfill(' ') << center(address, 15) << '|' << setw(15) << setfill(' ') << center(prev, 15) << '|' << setw(15) << center(data, 15) << '|' << setw(15) << center(next, 15) << '|' << endl;

os << setw(16) << setfill(' ') << ' ' << '\'' << setw(16) << setfill('-') << '\'' << setw(16) << '\'' << setw(16) << '\'' << endl;

os << endl;

curr = curr->next;

}

return os;

}

string center(const string &str, const int col_width)

{

// quick and easy (but error-prone) implementation

int padl = (col_width - str.length()) / 2;

int padr = (col_width - str.length()) - padl;

string strf = string(padl, ' ') + str + string(padr, ' ');

return strf;

}

//DoublyLinkedList.h header file

#ifndef DOUBLYLINKEDLIST_H

#define DOUBLYLINKEDLIST_H

#include

#include

#include "Node.h"

class DoublyLinkedList {

public:

DoublyLinkedList();

DoublyLinkedList(int);

~DoublyLinkedList();

void insert_back(int);

void insert_front(int);

void insert_at(int, int);

Node& find(int);

void delete_at(int);

Node& get_head();

Node& get_tail();

Node const& get_head() const;

Node const& get_tail() const;

private:

Node* head = nullptr;

Node* tail = nullptr;

DoublyLinkedList(DoublyLinkedList const&);

Node& operator=(DoublyLinkedList const&);

};

std::string center(const std::string &str, const int col_width);

std::ostream& operator<<(std::ostream &os, DoublyLinkedList const& ll);

#endif

//Node.h header file

#ifndef NODE_H

#define NODE_H

struct Node {

Node() : data(0), next(nullptr), prev(nullptr) {}

Node(int data) : data(data), next(nullptr), prev(nullptr) {}

int data;

Node* next;

Node* prev;

};

#endif

Finish the default constructor, parameterized contructor, destructor, insert_back, insert_at, find, and delete_at function for double linked node.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!