Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include template class DList{ struct Node{ T data_; Node* next_; Node* prev_; Node(const T& data=T{},Node* next=nullptr, Node* prev=nullptr){ data_=data; next_=next; prev_=prev; } }; Node* front_;
#include | |
template | |
class DList{ | |
struct Node{ | |
T data_; | |
Node* next_; | |
Node* prev_; | |
Node(const T& data=T{},Node* next=nullptr, Node* prev=nullptr){ | |
data_=data; | |
next_=next; | |
prev_=prev; | |
} | |
}; | |
Node* front_; | |
Node* back_; | |
public: | |
DList(){ | |
front_=nullptr; | |
back_=nullptr; | |
} | |
void push_front(const T& data); | |
void push_back(const T& data); | |
void pop_front(); | |
void pop_back(); | |
int getData(int data[]) const; | |
int getReverseData(int data[]) const; | |
~DList(); | |
}; | |
template | |
void DList | |
} | |
template | |
void DList | |
} | |
template | |
void DList | |
} | |
template | |
void DList | |
} | |
template | |
int DList | |
Node* curr=front_; | |
int numData=0; | |
while(curr!=nullptr){ | |
data[numData++]=curr->data_; | |
curr=curr->next_; | |
} | |
return numData; | |
} | |
template | |
int DList | |
Node* curr=back_; | |
int numData=0; | |
while(curr!=nullptr){ | |
data[numData++]=curr->data_; | |
curr=curr->prev_; | |
} | |
return numData; | |
} | |
template | |
DList | |
} | |
template |
Complete the push_front(), push_back(), pop_front(), pop_back() and destructor functions for a DList class.
Please answer the above question in C++ code language, thank you!
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