Question: IN C++ Implement a list using a doubly linked list. Requirements Files doubly_linked_list.h - contains the template definitions doubly_linked_list_tests.cpp - contains the test cases and
IN C++
Implement a list using a doubly linked list.
Requirements
Files
doubly_linked_list.h - contains the template definitions
doubly_linked_list_tests.cpp - contains the test cases and test driver (main)
Class
template
class DoublyLinkedList;
Functions (public)
DoublyLinkedList() - makes an empty list
Rule of Three
DoublyLinkedList(const DoublyLinkedList&) - constructs a copy of the given list
~DoublyLinkedList() - destroys this list
DoublyLinkedList& operator=(const DoublyLinkedList&) - assigns a copy of the given list
size_t size() - returns the number of elements in the list
Object& operator[](size_t) - returns a reference to the element at the specified index or throws std::out_of_range if the index is out of bounds.
void insert(size_t, const Object&) - insert the given object at the specified index or throws std::out_of_range if the index is out of bounds
void remove(index) - remove the object at the specified index or throws std::out_of_range if the index is out of bounds
Optional
DoublyLinkedList(DoublyLinkedList&&) - move-constructs a copy of the given (rvalue) list
DoublyLinkedList& operator=(DoublyLinkedList&&) - move-assigns a copy of the given (rvalue) list
void insert(size_t, Object&&) - insert the given (rvalue) object at the specified index or throws std::out_of_range if the index is out of bounds
const Object& operator[](size_t) const - returns a constant reference to the element at the specified index or throws std::out_of_range if the index is out of bounds.
iterator begin() - returns an iterator that points to the beginning of the list
const_iterator begin() const - returns an iterator that points to the beginning of the list
iterator end() - returns an iterator that points to the end of the list
const_iterator end() const - returns an iterator that points to the end of the list
Example
// make an empty list
DoublyLinkedList
// insert 3 values at the end of the list
list.insert(0, 1);
list.insert(1, 2);
list.insert(2, 3);
// get the size
size_t size = list.size();
// remove the middle element
list.remove(1);
// access the element at index 1
int value = list[1];
Header:
#ifndef DOUBLY_LINKED_LIST_H #define DOUBLY_LINKED_LIST_H
template
#endif // DOUBLY_LINKED_LIST_H
Test:
#include
int main() { // TODO(student): test your code }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
