need c++ format Interface Requirements 1.1 DLNode Your code should contain defin
ID: 3722840 • Letter: N
Question
need c++ format
Interface Requirements 1.1 DLNode Your code should contain definitions for a class DLNode which will be a doubly-linked container node, and a class DLList which will be the linked list of DLNode s. It is recommended that your linked list utilize both a head and tail pointer 1.2 DLList 12.1 EmptyListException 2 Files to Submit DLNode The DLNode will serve as a doubly-linked container for data of string Your DLNode should provide (at a minimum) the following public interface: Constructor You should provide a constructor that will take a data value and store it in the node. It should also set all the node's pointers to nullptr get data method returns the data value for the node get next method returns the node's next pointer (the pointer to the next node in the list) get prev method returns the node's prev pointer (the pointer to the previous node in the list). set_data method takes a data value as a parameter and uses it to set the node's data value set next method takes a pont o a DLNode as a parameter and uses it to set the node's next pointer set prev method takes a pointer to a DINode as a parameter and uses it to set the node's prev pointer. Implement this in "DLNode.h" and "DLNode.cpp" DLList The DLList will manage a doubly-linked list built from DLNode s. Internally, you will need storage for pointers to the head (and probably tai) of the list, as well as an integer to store the count of the number of items currently in the list. The list will throw an exception on any attempt to remove or read from an empty list. Your DLList should provide (at a minimum) the following public interface: Constructors You should provide a default constructor that initializes the list's pointers to nullptr. You should provide a copy constructor that will allow copying one list into the new list. (You might want to make use of the assignment operator for the copy constructor.) Destructor You should provide a destructor that will de-allocate all of the nodes in the list add front methood takes a data value as a parameter, and inserts that value at the beginning (head) of the list add back method takes a data value as a parameter, and inserts that value at the end (tail) of the list.Explanation / Answer
here is your program : ----------------->>>>>>>>>>>>
DLNode.h : ------------>>>>>>>
#ifndef _DLNODE_H
#define _DLNODE_H
#include<iostream>
using namespace std;
class EmptyListException{
public:
EmptyListException(string data){
cout<<data;
}
};
class DLNode{
string data;
DLNode *next;
DLNode *prev;
public:
DLNode();
DLNode(string data);
void set_data(string);
string get_data()const;
DLNode* get_next()const;
DLNode* get_prev()const;
void set_next(DLNode*);
void set_prev(DLNode*);
};
#endif
DLNode.cpp : ----------->>>>>>
#include "DLNode.h"
DLNode::DLNode(){
data = "";
next = NULL;
prev = NULL;
}
DLNode::DLNode(string data){
this->data = data;
next = NULL;
prev = NULL;
}
void DLNode::set_data(string data){
this->data = data;
}
void DLNode::set_next(DLNode *next){
this->next = next;
}
void DLNode::set_prev(DLNode *prev){
this->prev = prev;
}
DLNode* DLNode::get_next()const{
return next;
}
DLNode* DLNode::get_prev()const{
return prev;
}
string DLNode::get_data()const{
return data;
}
DLList.h : ------------->>>>>>.
#ifndef _DLLIST_H
#define _DLLIST_H
#include "DLNode.cpp"
class DLList{
DLNode *front;
DLNode *back;
int size;
public:
DLList();
DLList(const DLList &other);
DLList& operator=(const DLList &other);
~DLList();
void add_front(string data);
void add_back(string data);
string peek_front()const;
string peek_back()const;
string remove_front();
string remove_back();
DLNode* getFront()const;
bool remove_value(string data);
bool contains(string data);
bool is_empty()const;
unsigned int count()const;
string* as_array();
string* as_array_reverse();
void clear();
friend ostream& operator<<(ostream &out,const DLList &other);
};
#endif
DLList.cpp : ------------>>>>>>>>>.
#include "DLList.h"
DLList::DLList(){
size = 0;
front = NULL;
back = NULL;
}
DLList::DLList(const DLList &other){
*this = other;
}
DLList& DLList::operator=(const DLList &other){
string temp;
DLNode *tmp = other.front;
for(int i = 0;i<other.size;i++){
temp = tmp->get_data();
this->add_front(temp);
tmp = tmp->get_next();
}
return *this;
}
void DLList::add_front(string data){
DLNode *temp = new DLNode;
temp->set_data(data);
temp->set_next(NULL);
temp->set_prev(NULL);
if(is_empty()){
front = temp;
back = front;
size++;
return;
}
temp->set_next(front);
front->set_prev(temp);
front = temp;
size++;
}
void DLList::add_back(string data){
DLNode *temp = new DLNode;
temp->set_data(data);
temp->set_next(NULL);
temp->set_prev(NULL);
if(is_empty()){
front = temp;
back = front;
size++;
return;
}
temp->set_prev(back);
back->set_next(temp);
back = temp;
size++;
}
string DLList::peek_front()const{
if(is_empty()){
throw EmptyListException("List Is Empty");
}
return front->get_data();
}
string DLList::peek_back()const{
if(is_empty()){
throw EmptyListException("List Is Empty");
}
return back->get_data();
}
DLList::~DLList(){
clear();
delete front;
delete back;
}
string DLList::remove_back(){
if(is_empty()){
throw EmptyListException("List Is Empty");
}
string temp;
if(size == 1){
temp = front->get_data();
delete front;
front = back = NULL;
size = 0;
return temp;
}
DLNode *tmp = back;
temp = back->get_data();
back = back->get_prev();
back->set_next(NULL);
delete tmp;
size--;
return temp;
}
string DLList::remove_front(){
if(is_empty()){
throw EmptyListException("List Is Empty");
}
string temp;
if(size == 1){
temp = front->get_data();
delete front;
front = back = NULL;
size = 0;
return temp;
}
DLNode *tmp = front;
temp = back->get_data();
front = front->get_next();
front->set_prev(NULL);
delete tmp;
size--;
return temp;
}
bool DLList::contains(string data){
if(is_empty()){
throw EmptyListException("List Is Empty");
}
DLNode *temp = front;
for(int i = 0;i<size;i++){
if(temp->get_data() == data){
return true;
}
temp = temp->get_next();
}
return false;
}
bool DLList::remove_value(string data){
if(is_empty()){
return false;
}
DLNode *temp = front;
for(int i = 0;i<size;i++){
if(temp->get_data() == data){
if(temp == front){
remove_front();
return true;
}
if(temp == back){
remove_back();
return true;
}
temp->get_prev()->set_next(temp->get_next());
temp->get_next()->set_prev(temp->get_prev());
size--;
delete temp;
return true;
}
temp = temp->get_next();
}
return false;
}
unsigned int DLList::count()const{
return size;
}
void DLList::clear(){
DLNode *temp = front;
int n = size;
for(int i = 0;i<n;i++){
remove_front();
}
}
bool DLList::is_empty()const{
if(size == 0){
return true;
}
return false;
}
string* DLList::as_array(){
string *arr = new string[size];
DLNode *temp = front;
for(int i = 0;i<size;i++){
arr[i] = temp->get_data();
temp = temp->get_next();
}
return arr;
}
string* DLList::as_array_reverse(){
string *arr = new string[size];
DLNode *temp = back;
for(int i = 0;i<size;i++){
arr[i] = temp->get_data();
temp = temp->get_prev();
}
return arr;
}
DLNode* DLList::getFront()const{
return front;
}
ostream& operator<<(ostream &out,const DLList &other){
DLNode *temp = other.getFront();
for(int i = 0;i<other.count();i++){
out<<temp->get_data()<<", ";
temp = temp->get_next();
}
return out;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.