Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following problem is pretty self explanatory! Keep in mind, the coding language used is C++ on Visual Data Studio! I will be attaching a

The following problem is pretty self explanatory! Keep in mind, the coding language used is C++ on Visual Data Studio! I will be attaching a partial code labeled as Datalist down below that needs to be modified to meet the requirements asked for in the question. Read the problem carefully as it isn't divided into separate parts despite it looking like it. Include numerous comments throughout the code as well as the distinct outputs once the program is ran and I will rate afterwards accordingly!

image text in transcribed

The Datalist code, that needs to be modified, will be pasted down below:

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /* * File: DataList.cpp * Author: dms147 * * Created on February 18, 2020, 9:44 PM */ #include #include #include using namespace std; // Class Node represents a single node in a linked list. class Node{ public: // The following attributes are declared public // for the convenience of accessing them. int val; Node *next; Node *prev; // Constructor Function for creating a node in a linked list // with initial value of aVal Node(int aVal){ val = aVal; next = NULL; prev = NULL; } // Destructor function, optional ~Node(){ //delete next; //delete prev; } }; // Class DataList represents a simple type of doubly-linked list, // where each node has an integer value class DataList{ public: // Default Constructor for // creating an empty linked list DataList(){ // The pointers to the head and tail of the list mHead = NULL; mTail = NULL; } // An alternate constructor function allowing the // initialization of a linked list with a vector of given values. DataList(vector vals){ mHead = NULL; mTail = NULL; // Populate the linked list with values // in the vector parameter vals for(int i=0; ival next; } cout next; if (curNode->valappend(curNode); else dListH->append(curNode); curNode = nextNode; } // Clearing this linked list after the splitting mHead = NULL; mTail = NULL; vector dLists; dLists.push_back(dListL); dLists.push_back(dListH); return dLists; } // This function appends a node to the end // of this linked list. void append(Node* aNode){ if(mHead==NULL) mHead = aNode; else mTail->next = aNode; aNode->prev = mTail; aNode->next = NULL; mTail = aNode; } private: Node* mHead; Node* mTail; }; /* int main(){ // Testing code for the function splitByVal of the // class DataList; vector vals{3, 5, 9, 1,-5, 0}; DataList dList(vals); cout print(); cout " print(); return 0; } */
Part 1 The class DataList (see attached) we created in class gives a simple implementation of linked lists. In this part of the project you will expand the class DataList by adding one of the following functions to the class. You will also add testing code in the main function of the DataList class to demonstrate the correctness of the function you add on at least 5 different test cases. 1. The function splitByVals splits the linked list into a set of smaller linked lists based on the values of nodes in the list. More precisely, the function splitByVals will take a sorted integer array/vector vals and return an array or vector dLists of linked lists, where dLists[0] contains nodes in the original list whose values are less than vals[0], and dLists[i] contains nodes in the original linked list whose values are between vals[i-1] and For example, if dList is a linked list in which the node values are 3, 6, -2, 3,9, 0, 7, 2, 1, and -8, and vals is an integer array/vector containing values -5, 0, 5, and 10, in that order. Then a function call of dList.splitByVals(vals) will produce a vector/array dLists of 5 linked lists, where dLists[0] contains a node of value -8 (values k, where k=(n+1)/2 and n is the length of the linked list. This means that for a linked list of size n = 10, the 1st node of Iremains the 1st node of I, the 6-th node of/ becomes the 2nd node, the 2nd node becomes the 3rd node, and so on, after / is shuffled. Consider the example given in part I again. The order of nodes should be the following after a function call of dList.shuffle(): 3,0, 6, 7, -2, 2, 3, 1, 9, -8. For this part, you must add your code to the attached cpp file and submit the modified file (that runs) as your solution. Part 1 The class DataList (see attached) we created in class gives a simple implementation of linked lists. In this part of the project you will expand the class DataList by adding one of the following functions to the class. You will also add testing code in the main function of the DataList class to demonstrate the correctness of the function you add on at least 5 different test cases. 1. The function splitByVals splits the linked list into a set of smaller linked lists based on the values of nodes in the list. More precisely, the function splitByVals will take a sorted integer array/vector vals and return an array or vector dLists of linked lists, where dLists[0] contains nodes in the original list whose values are less than vals[0], and dLists[i] contains nodes in the original linked list whose values are between vals[i-1] and For example, if dList is a linked list in which the node values are 3, 6, -2, 3,9, 0, 7, 2, 1, and -8, and vals is an integer array/vector containing values -5, 0, 5, and 10, in that order. Then a function call of dList.splitByVals(vals) will produce a vector/array dLists of 5 linked lists, where dLists[0] contains a node of value -8 (values k, where k=(n+1)/2 and n is the length of the linked list. This means that for a linked list of size n = 10, the 1st node of Iremains the 1st node of I, the 6-th node of/ becomes the 2nd node, the 2nd node becomes the 3rd node, and so on, after / is shuffled. Consider the example given in part I again. The order of nodes should be the following after a function call of dList.shuffle(): 3,0, 6, 7, -2, 2, 3, 1, 9, -8. For this part, you must add your code to the attached cpp file and submit the modified file (that runs) as your solution

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

More Books

Students also viewed these Databases questions

Question

b. Explain how you initially felt about the communication.

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago

Question

a. When did your ancestors come to the United States?

Answered: 1 week ago