Question: Book implementation explained in class: + - - - - - - - + + - - - - - - - + + -
Book implementation explained in class:
Dummy Node Node Dummy
Head Trailer
Assignment implementation:
NULL Node Node NULL
Head Trailer
Part : Implementation
### DNode Class Implementation
Create a class DNode to represent the nodes in the doubly linked list.
#### DNode.h Header File
Member Variables Private:
int elem; Element stored in the node
DNode prev; Pointer to the previous node
DNode next; Pointer to the next node
Member Variables Public:
static int activeNodes; Static variable to track the number of active nodes
Member Functions Private:
Inside the constructor, increment activeNodes by one
whenever a node is created
DNodeint e DNode p nullptr, DNode n nullptr; Constructor
Member Functions Public:
Inside the destructor, decrement activeNodes by one
whenever a node is destroyed
~DNode;
Refer to page in the textbook for the class definition structure.
### DLinkedList Class Implementation
Create a class DLinkedList to encapsulate the functionality of a doubly
linked list.
#### DLinkedList.h Header File
Member Variables Private:
DNode head; Pointer to the first node
DNode trailer; Pointer to the last node
int size; Stores the current number of elements in the list
Member Functions Public:
DLinkedList; Constructor
~DLinkedList; Destructor
bool empty const; Check if the list is empty
const int& front const; Get front element
const int& back const; Get back element
void addFrontconst int& e; Add to the front of the list
void addBackconst int& e; Add to the back of the list
void removeFront; Remove front item from the list
void removeBack; Remove back item from the list
Print the list starting from the head when the parameter front value is true,
and prints starting from the trailer when the parameter front value is false.
void printbool front true const;
int size const; Returns the current number of elements in the list
int activeNodeCount const; Return the count of active DNodes
It is your choice whether to utilize the add and remove methods explained in class
for implementing the DLinkedList class.
#### DLinkedList.cpp Implementation File
Implement the functions declared in DLinkedList.h
Refer to pages in the textbook for guidance on the class structure.
### Main Function Implementation
Write the main function in a separate cpp file name it main.cpp to demonstrate
the functionality of the DLinkedList class.
#### main.cpp
Include the neccesary files
Initialize the static variable activeNodes with before main function
example code:
#include
int DNode::activeNodes ;
int main
Implement the main function
#### Main Function Details:
Create an instance of DLinkedList.
Add elements to the front of the list.
Add elements to the back of the list.
Traverse the list from head and print elements.
Traverse the list from trailer and print elements in reverse order.
Remove one element from the front and one from the back.
Print the list again after removals.
Add another element to the front and one to the back.
Print the list after all operations.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
