Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to make the list.hpp file in c + + based on the list.h file, I would appreciate it if you could explain each

I need to make the list.hpp file in c++ based on the list.h file, I would appreciate it if you could explain each part in detail step by step and show me the final version that was integrated at the end.
A header file List.h is provided, which contains the interfaces of the doubly-linked list class template List. In particular, it contains a nested Node structure, and two nested iterators class (iterator and const_iterator). You cannot change anything in the List.h file.
List.h
#ifndef DL_LIST_H
#define DL_LIST_H
#include
#include
namespace cop4530{
template
class List {
private:
// nested Node class
struct Node {
T data;
Node *prev;
Node *next;
Node(const T & d = T{}, Node *p = nullptr, Node *n = nullptr)
: data{d}, prev{p}, next{n}{}
Node(T && d, Node *p = nullptr, Node *n = nullptr)
: data{std::move(d)}, prev{p}, next{n}{}
};
public:
//nested const_iterator class
class const_iterator {
public:
const_iterator();
const T & operator*() const;
const_iterator & operator++();
const_iterator operator++(int);
const_iterator & operator--();
const_iterator operator--(int);
bool operator==(const const_iterator &rhs) const;
bool operator!=(const const_iterator &rhs) const;
protected:
Node *current;
T & retrieve() const;
const_iterator(Node *p);
friend class List;
};
class iterator : public const_iterator {
public:
iterator();
T & operator*();
const T & operator*() const;
iterator & operator++();
iterator operator++(int);
iterator & operator--();
iterator operator--(int);
protected:
iterator(Node *p);
friend class List;
};
public:
List();
List(const List &rhs);
List(List && rhs);
explicit List(int num, const T& val = T{});
List(const_iterator start, const_iterator end);
List (std::initializer_list iList);
~List(); // destructor
const List& operator=(const List &rhs);
List & operator=(List && rhs);
List& operator=(std::initializer_list iList);
int size() const;
bool empty() const;
void clear();
void reverse();
T& front();
const T& front() const;
T& back();
const T& back() const;
void push_front(const T & val);
void push_front(T && val);
void push_back(const T & val);
void push_back(T && val);
void pop_front();
void pop_back();
void remove(const T &val);
template
void remove_if(PREDICATE pred);
void print(std::ostream& os, char ofc ='') const;
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
iterator insert(iterator itr, const T& val);
iterator insert(iterator itr, T && val);
iterator erase(iterator itr);
iterator erase(iterator start, iterator end);
private:
int theSize;
Node *head;
Node *tail;
void init();
};
template
bool operator==(const List & lhs, const List &rhs);
template
bool operator!=(const List & lhs, const List &rhs);
template
std::ostream & operator(std::ostream &os, const List &l);
#include "List.hpp"
}// end of namespace 4530
#endif
image text in transcribed

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

Students also viewed these Databases questions