Answered step by step
Verified Expert Solution
Link Copied!

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 4: Doubly Linked List Implementation
Develop a Doubly Linked List in C++ using object-oriented 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:
Assignm]ent 4 implementation:
Part 1: Implementation
Node Class Implementation (Named it DNode)
Develop a class named DNode to represent a node in the 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
Refer to page 125 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 addFront(const int & e); // add to front of list void addBack(const 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 print(const 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 (main.cpp) 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:
image text in transcribed

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

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions

Question

What are the advantages and disadvantages of cloud computing?

Answered: 1 week ago