Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment 4 : Doubly Linked List Implementation Develop a Doubly Linked List in C + + using object - oriented programming principles, and ensure that
Assignment : Doubly Linked List Implementation
Develop a Doubly Linked List in C using objectoriented programming principles, and ensure that your implementation does not utilize dummy nodes sentinels This assignment consists of creating a Node class DNode a Doubly Linked List class DLinkedList and a main function to test the Doubly Linked List functionality.
Book implementation explained in class:
Assignment implementation:
Part : Implementation
Node Class Implementation Named it DNode
Develop a class named DNode to represent a node in the list.
DNode. 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
Refer to page in the textbook for the class definition structure.
Doubly Linked List Class Implementation Name it DLinkedList
Create a class named DLinkedList that encapsulates 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
Member Functions Public:
DLinkedList;
DLinkedList; destructor
bool empty const; is list empty?
const int& front const; get front element
const int & back const; get last element
void addFrontconst int & e; add to front of list void addBackconst int & e; add to back of list
void removeFront; remove front item from list and inform the user that was removed
void removeBack; remove back item from list and inform the user that was removed void printconst bool& front True; prints starting from the head when the parameter front value is true, and prints starting from the trailer when the parameter front value is false.
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 DLinkedList class member functions declared in DLinkedList.h
Main Function Implementation
Write the main function in a separate cpp file maincpp to demonstrate the functionality of your DLinkedList.
Main Function Structure
Initialization:
Begin by creating an instance of the DLinkedList class. This instance will be used throughout the demonstration to manage a list of elements.
Adding Elements:
Front Addition: Add three elements to the front of the list. This action demonstrates the list's ability to add elements efficiently in front of the list.
Back Addition: Add two elements to the back of the list. This showcases the list's capability to add elements efficiently at the end of the list.
First Traversal and Print:
Print from Head: Traverse the list starting from the head and print all elements. This initial printout provides a view of the list after the initial additions.
Print from Trailer: Traverse the list starting from the trailer back and print all elements in reverse order. This demonstrates the doubly linked list's bidirectional traversal capability.
Removing Elements:
Front Removal: Remove one element from the front of the list. This operation tests the list's ability to handle deletions at the beginning.
Back Removal: Remove one element from the back of the list. Similarly, this tests the list's ability to handle deletions at the end.
Second Traversal and Print:
Repeat the process of printing the list from both the head and the trailer after the removal operations. This provides insight into how the list structure changes with element removal.
Additional Additions:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started