Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Finish implementing the List class (in list.h): Implement a following member functions: removeAt : Remove the node at the specified index. Return the int value

Finish implementing the List class (in list.h):

Implement a following member functions: removeAt : Remove the node at the specified index. Return the int value contained at the now removed node. Exit program if an invalid index is provided. remove : Remove the provided value if it is contained in the list. Return true if the value was found and remove, return false if no changes were made to the list. at : Returns the int value contained at the node at the provided index. Exit program if an invalid index is provided. valueOf : Given a ListNode pointer, return the given value getNext : Given a ListNode pointer, return a pointer to its next ListNode getPrevious : Given a ListNode pointer, return a pointer to its previous ListNode In the list.h file, do not modify any of the contents of the List class unless they are marked with a TODO comment. List.h:

class ListNode { private: int data; ListNode* prev; ListNode* next; public: ListNode() { prev = next = NULL; } ListNode(int d, ListNode* p, ListNode* n) { data = d; prev = p; next = n; } friend class List; }; class List { private: ListNode* head; ListNode* tail; public: List() { head = tail = NULL; } ~List(); bool isEmpty() { return head == NULL; } bool contains(int value); void addToHead(int value); void addToTail(int value); int removeHead(); int removeTail(); int removeAt(int index); bool remove(int value); int at(int index); int valueOf(const ListNode* elem); const ListNode* getNext(const ListNode* node); const ListNode* getPrevious(const ListNode* node); const ListNode* getHead() { return head; } const ListNode* getTail() { return tail; } }; List::~List() { while (!isEmpty()) removeTail(); } bool List::contains(int value) { ListNode *temp = head; while (temp != NULL && temp->data != value) temp = temp->next; return temp != NULL; } void List::addToHead(int value) { if (isEmpty()) { head = tail = new ListNode(value, NULL, NULL); } else  { head = new ListNode(value, NULL, head); head->next->prev = head; } } void List::addToTail(int value) { if (isEmpty()) { head = tail = new ListNode(value, NULL, NULL); } else  { tail = new ListNode(value, tail, NULL); tail->prev->next = tail; } } int List::removeHead() { int value = head->data; if (head == tail) { delete tail; head = tail = NULL; } else  { head = head->next; delete head->prev; head->prev = NULL; } return value; } int List::removeTail() { int value = head->data; if (head == tail) { delete tail; head = tail = NULL; } else  { tail = tail->prev; delete tail->next; tail->next = NULL; } return value; } int List::removeAt(int index) { // TODO: implement removeAt } bool List::remove(int value) { // TODO: implement remove } int List::at(int index) { // TODO: implement at } int valueOf(const ListNode* elem) { // TODO: implement valueOf } const ListNode* List::getNext(const ListNode* node) { // TODO: imoplement getNext } const ListNode* List::getPrevious(const ListNode* node) { // TODO: implement getPrevious }

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

Step: 3

blur-text-image

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

Intelligent Information And Database Systems Third International Conference Achids 2011 Daegu Korea April 2011 Proceedings Part 2 Lnai 6592

Authors: Ngoc Thanh Nguyen ,Chong-Gun Kim ,Adam Janiak

2011th Edition

3642200419, 978-3642200410

More Books

Students also viewed these Databases questions

Question

Write the Chinese numeral as a HinduArabic numeral.

Answered: 1 week ago

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago

Question

Define Management or What is Management?

Answered: 1 week ago

Question

d. What language(s) did they speak?

Answered: 1 week ago