Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . Write a class List for a doubly - linked list of characters, using a circular linked list with a dummy node ( List

1. Write a class List for a doubly-linked list of characters, using a circular linked list
with a dummy node (List.h, List.cc). The nodes (Element) should be declared as
a private nested class. Also declare iterator as a public nested class. For simplicity,
you do not need to implement const_iterator.
You should implement the following member functions:
Default constructor: initializes the list to an empty list.
Destructor: deletes all nodes in the list.
begin(), end(): return iterators that point to the beginning and one-past-theend
of the list. Note that if the list is empty, then begin()== end().
void insert(iterator it, char c): inserts the character c into the position
specified by the iterator it. If it == end(), the character is appended to the
list.
void erase(iterator it): erases the character at the position specified by the
iterator it. If it == end(), this function does nothing.
Make sure that List is a friend of iterator. For the iterator nested class, implement
the following member functions:
A default constructor which initializes the pointer to nullptr.
A private constructor which takes a pointer to Element and initializes itself to the
pointer. Making the constructor private means that only List member functions
can initialize an iterator directly.
The pre-increment operator (++) which moves to the next element. You can
assume that the iterator is not one-past-the-end of the list.
The pre-decrement operator (--) which moves to the previous element. You can
assume that the iterator is not at the beginning of the list.
The dereference operator (*). Provide two versions of the dereference operator:
one returning a reference to the character data, and another returning a constant
reference.
The comparison operators == and != which compare the pointers.
Modify the posted solution of Assignment 4 Question 1 to use the List class instead
of the STL list class. Put this in prob1.cc.

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_2

Step: 3

blur-text-image_3

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

When is the appropriate time to write a business plan?

Answered: 1 week ago