The document provides instructions to complete the implementation of a doubly linked list (List) and queue (Queue) data structures in C++. It includes a List.h file with the definition of the List class and its iterator. There are TODO comments throughout for various methods that need to be implemented, including constructors, destructors, iterators, capacity functions, element access functions, insertion/removal functions, and an equality operator for Queue. It also includes a Queue.h file with the definition of the Queue class using List as its underlying container.
Historical philosophical, theoretical, and legal foundations of special and i...
C++ LIST AND QUEUE IMPLEMENTATION
1. Please code in C++ and do only the TO DOs and all of them. There are two files.
List.h:
#pragma once
#include // size_t
#include // std::bidirectional_iterator_tag
#include // std::is_same, std::enable_if
template
class List {
private:
struct Node {
Node *next, *prev;
T data;
explicit Node(Node* prev = nullptr, Node* next = nullptr)
: next{next}, prev{prev} {}
explicit Node(const T& data, Node* prev = nullptr, Node* next = nullptr)
: next{next}, prev{prev}, data{data} {}
explicit Node(T&& data, Node* prev = nullptr, Node* next = nullptr)
: next{next}, prev{prev}, data{std::move(data)} {}
};
template
class basic_iterator {
public:
using iterator_category = std::bidirectional_iterator_tag;
using value_type = T;
using difference_type = ptrdiff_t;
using pointer = pointer_type;
using reference = reference_type;
private:
friend class List;
3. basic_iterator& operator--() {
// TODO
}
// Postfix Decrement: a--
basic_iterator operator--(int) {
// TODO
}
bool operator==(const basic_iterator& other) const noexcept {
// TODO
}
bool operator!=(const basic_iterator& other) const noexcept {
// TODO
}
};
public:
using value_type = T;
using size_type = size_t;
using difference_type = ptrdiff_t;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = value_type*;
using const_pointer = const value_type*;
using iterator = basic_iterator;
using const_iterator = basic_iterator;
private:
Node head, tail;
size_type _size;
public:
4. List() {
// TODO - Don't forget to initialize the list beforehand
}
List( size_type count, const T& value ) {
// TODO - Don't forget initialize the list beforehand
}
explicit List( size_type count ) {
// TODO - Don't forget initialize the list beforehand
}
List( const List& other ) {
// TODO - Don't forget initialize the list beforehand
}
List( List&& other ) {
// TODO - Don't forget initialize the list beforehand
}
~List() {
// TODO
}
List& operator=( const List& other ) {
// TODO
}
List& operator=( List&& other ) noexcept {
// TODO
}
reference front() {
// TODO
}
const_reference front() const {
// TODO
}
reference back() {
// TODO
}
5. const_reference back() const {
// TODO
}
iterator begin() noexcept {
// TODO
}
const_iterator begin() const noexcept {
// TODO
}
const_iterator cbegin() const noexcept {
// TODO
}
iterator end() noexcept {
// TODO
}
const_iterator end() const noexcept {
// TODO
}
const_iterator cend() const noexcept {
// TODO
}
bool empty() const noexcept {
// TODO
}
size_type size() const noexcept {
// TODO
}
6. void clear() noexcept {
// TODO
}
iterator insert( const_iterator pos, const T& value ) {
// TODO
}
iterator insert( const_iterator pos, T&& value ) {
// TODO
}
iterator erase( const_iterator pos ) {
// TODO
}
void push_back( const T& value ) {
// TODO
}
void push_back( T&& value ) {
// TODO
}
void pop_back() {
// TODO
}
void push_front( const T& value ) {
// TODO
}
void push_front( T&& value ) {
// TODO
}
7. void pop_front() {
// TODO
}
/*
You do not need to modify these methods!
These method provide the non-const complement
for the const_iterator methods provided above.
*/
iterator insert( iterator pos, const T & value) {
return insert((const_iterator &) (pos), value);
}
iterator insert( iterator pos, T && value ) {
return insert((const_iterator &) (pos), std::move(value));
}
iterator erase( iterator pos ) {
return erase((const_iterator&)(pos));
}
};
/*
You do not need to modify these methods!
These method provide a overload to compare const and
non-const iterators safely.