below is my delist.cpp file #include "delist.h" #include <iostream> using namespace std;…
- User
below is my delist.cpp file #include "delist.h" #include
using namespace std;
// Add your function implementations here
DEList::DEList() { head = nullptr; tail = nullptr; Itemcount = 0; }
DEList::~DEList() { while (head != nullptr){ pop_front(); } }
bool DEList:: empty() const { return (Itemcount == 0); }
int DEList:: size() const { return Itemcount; }
int DEList:: front() const { int retval; if (head == NULL){ return -1; } retval = head -> val; return retval;
}int DEList:: back() const { int retval; if (head == NULL){ return -1; } retval = tail -> val; return retval;
}void DEList:: push_front(int new_val) { DEItem* ptr = new DEItem; ptr -> val = new_val; ptr -> next = head; ptr -> prev = nullptr; if (head != nullptr){ head -> prev = ptr; } else{ tail = ptr; } head = ptr; Itemcount++; }
void DEList:: push_back(int new_val) { DEItem *ptr; ptr = new DEItem; ptr -> val = new_val; ptr -> next = nullptr;
if (head == nullptr){ head = ptr; tail = ptr; head -> prev = nullptr; } else{ tail -> next = ptr; ptr -> prev = tail; tail = ptr; } Itemcount++; }
void DEList:: pop_front() { if (!empty()){ DEItem* ptr = head; head = head -> next; if (head == nullptr){ tail = nullptr; } else{ head -> prev = nullptr; } delete ptr; Itemcount--; } else{ return; } }
void DEList:: pop_back() { if (!empty()){ DEItem* ptr = tail; tail = tail -> prev;
codeif (tail == nullptr){ head = nullptr; } else{ tail -> next = nullptr; } delete ptr; Itemcount--;} else{ return; } }
string DEList:: conv_to_string() const { string retval; DEItem* ptr = head;
while (ptr != nullptr){ retval += to_string(ptr -> val); if (ptr -> next != nullptr){ retval += " "; } ptr = ptr -> next; } return retval; }
- Assistant