1. (30 points) Implement the Bag class discussed in lecture in your class library. However, rather than using vectors, implement the class using the linked list class provided in the starter code...

1. (30 points) Implement the Bag class discussed in lecture in your class library. However, rather than using vectors, implement the class using the linked list class provided in the starter code. 2. (30 points) Now implement the linked list class covered during the lecture. Create a second version of the Bag class in lecture in your class library. However, replace the STL list classes with your version of a linked list class. 3. (40 points) Provide one or more test programs that tests the behavior of your Bag class. Start by writing a test plan using the Unit Test template attached to the assignment on Blackboard. Implement the required code to show those tests executing. Add the Excel file to your GitHub repository in the docs folder.


Test Scripts Unit Tests for Test ID: Preconditions: Input Data: Expected Result: Postconditions: #pragma once #include template class List { private: class Node { public: T data; Node* prev; Node* next; }; Node* head = nullptr; Node* tail = nullptr; void setupList() { Node* newNode = new Node(); newNode->next = nullptr; newNode->prev = nullptr; head = newNode; tail = newNode; } void deleteListContents() { Node* temp = nullptr; Node* current = head; while (current != nullptr) { temp = current->next; delete current; current = temp; } } public: List() : head(nullptr), tail(nullptr) {} List(T newData) { setupList(); head->data = newData; } List(List& rhs) { // copy constructor deleteListContents(); head = rhs.head; tail = rhs.tail; } ~List() {// And a destructor deleteListContents(); } bool empty() { return (head == nullptr); } void push_front(T data) { Node* newNode = new Node(); newNode->data = data; newNode->next = head; newNode->prev = nullptr; if (empty()) { head = newNode; tail = newNode; } else { head->prev = newNode; head = newNode; } } void push_back(T data) { Node* newNode = new Node(); newNode->data = data; newNode->next = nullptr; newNode->prev = tail; if (empty()) { tail = newNode; head = newNode; } else { tail->next = newNode; tail = newNode; } } void pop_back() { Node *lastNode = tail; if (lastNode != nullptr) { tail = tail->prev; tail->next = nullptr; delete lastNode; } } T front() { if (!empty()) { return head->data; } else { // This is drastic, and should be handled using an exception handler std::cout < "exception:="" list="" is="" empty."="">< std::endl;="" exit(1);="" }="" }="" t="" back()="" {="" if="" (!empty())="" {="" return="" tail-="">data; } else { // This is drastic, and should be handled using an exception handler std::cout < "exception:="" list="" is="" empty."="">< std::endl;="" exit(1);="" }="" }="" void="" traverse(void="" (*doit)(t="" data))="" {="" node*="" current="head;" while="" (current="" !="nullptr)" {="" doit(current-="">data); current = current->next; } } };
Jan 24, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here