Question: data structure using c++ please don't use predefined functions when you answer dont use removeAt(), insertAt(),insertEnd, retrieveAt(),replaceAt, etc inside implementation of the functions. part 1:
data structure using c++
please don't use predefined functions when you answer
dont use removeAt(), insertAt(),insertEnd, retrieveAt(),replaceAt, etc inside implementation of the functions.
part 1:
1. Modify the arrayListType by adding a member function that increase each element in the list by a constant number that it takes as a parameter.
This member function does not return any value. For example,
if the list L contains the elements 2,1,3,4,5,3,0 and you call the member function as in L.incrementByConstant(3);
The list content will then be changed to 5,4,6,7,8,6,3
2. Modify the arrayListType by adding a member function that checks every 2 consecutive elements and
make them in ascending or descending order depending on a parameter
value (letter a means ascending and letter d means descending). For example,
if the list L contains the elements 2,1,3,4,5,3,0 and you call the member function as in L.sortEach2(a);
The list content will then be changed to 1,2,3,4,3,5,0 if the list L contains
the elements 2,1,3,4,5,3,0 and you call the member function as in L.sortEach2(d);
The list content will then be changed to 2,1,4,3,5,3,0
3. Modify the arrayListType by adding a member function that duplicate each item that is
greater than a value that is sent to the function as a parameter and remove the items that
are smaller than the parameter. For example,
if a list L contains the elements 2,1,3,4,5,3,0 and you call the member function as in L.duplicateORremove(3);
The list content will then be changed to 3,4,4,5,5,3
4. Modify the arrayListType by adding a member function that creates 2 new lists from the elements in the list.
The fist list should store the elements that are less than a parameter value and the rest of the elements should go to the second list.
The original list should not be modified. The 2 new lists can be returned from the function through reference parameters.
For example, if a list L contains the elements 2,1,3,4,5,3,0
And you have tow other lists, L1,L2 and you call the member function as in L.split(3,L1,L2);
The list L content will not be changed, list L1 will contain 2,1,0 and the list l2 will contain 3,4,5,3.

#ifndef H_LinkedList #define H_LinkedList #include using namespace std; //*********************************************************** // Author: D.S. Malik // // This class specifies the members to implement the basic // properties of a linked list. This is an abstract class. // We cannot instantiate an object of this class. //*********************************************************** template struct nodeType { Type info; nodeType * link; }; template class linkedListType { public: const linkedListType & operator = (const linkedListType &); //Overload the assignment operator. void initializeList(); //Initialize the list to an empty state. //Postcondition: this->first = NULL, this->last = NULL, this->count = 0; bool isEmptyList() const; //Function to determine whether the list is empty. //Postcondition: Returns true if the list is empty, otherwise // it returns false. void print() const; //Function to output the data contained in each node. //Postcondition: none int length() const; //Function to return the number of nodes in the list. //Postcondition: The value of this->count is returned. void destroyList(); //Function to delete all the nodes from the list. //Postcondition: this->first = NULL, this->last = NULL, this->count = 0; Type front() const; //Function to return the this->first element of the list. //Precondition: The list must exist and must not be empty. //Postcondition: If the list is empty, the program terminates; // otherwise, the this->first element of the list is returned. Type back() const; //Function to return the this->last element of the list. //Precondition: The list must exist and must not be empty. //Postcondition: If the list is empty, the program // terminates; otherwise, the this->last // element of the list is returned. virtual bool search(const Type& searchItem) const = 0; //Function to determine whether searchItem is in the list. //Postcondition: Returns true if searchItem is in the list, // otherwise the value false is returned. virtual void insertfirst(const Type& newItem) = 0; //Function to insert newItem at the beginning of the list. //Postcondition: this->first points to the new list, newItem is // inserted at the beginning of the list, this->last points to // the this->last node in the list, and this->count is incremented by // 1. virtual void insertlast(const Type& newItem) = 0; //Function to insert newItem at the end of the list. //Postcondition: this->first points to the new list, newItem is // inserted at the end of the list, this->last points to the // this->last node in the list, and this->count is incremented by 1. virtual void deleteNode(const Type& deleteItem) = 0; //Function to delete deleteItem from the list. //Postcondition: If found, the node containing deleteItem is // deleted from the list. this->first points to the this->first node, // this->last points to the this->last node of the updated list, and // this->count is decremented by 1. linkedListType(); //default constructor //Initializes the list to an empty state. //Postcondition: this->first = NULL, this->last = NULL, this->count = 0; linkedListType(const linkedListType & otherList); //copy constructor ~linkedListType(); //destructor //Deletes all the nodes from the list. //Postcondition: The list object is destroyed. protected: int count; //variable to store the number of list elements nodeType * first; //pointer to the this->first node of the list nodeType * last; //pointer to the this->last node of the list private: void copyList(const linkedListType & otherList); //Function to make a copy of otherList. //Postcondition: A copy of otherList is created and assigned // to this list. }; template bool linkedListType ::isEmptyList() const { return (this->first == NULL); } template linkedListType ::linkedListType() //default constructor { this->first = NULL; this->last = NULL; this->count = 0; } template void linkedListType ::destroyList() { nodeType * temp; //pointer to deallocate the memory //occupied by the node while (this->first != NULL) //while there are nodes in the list { temp = this->first; //set temp to the current node this->first = this->first->link; //advance this->first to the next node delete temp; //deallocate the memory occupied by temp } this->last = NULL; //initialize this->last to NULL; this->first has already //been set to NULL by the while loop this->count = 0; } template void linkedListType ::initializeList() { destroyList(); //if the list has any nodes, delete them } template void linkedListType ::print() const { nodeType * current; //pointer to traverse the list current = this->first; //set current point to the this->first node while (current != NULL) //while more data to print { cout info link; } cout ::length() const { return this->count; } template Type linkedListType ::front() const { assert(this->first != NULL); return this->first->info; //return the info of the this->first node } //end front template Type linkedListType ::back() const { assert(this->last != NULL); return this->last->info; //return the info of the this->last node } //end back template void linkedListType ::copyList(const linkedListType & otherList) { nodeType * newNode; //pointer to create a node nodeType * current; //pointer to traverse the list if (this->first != NULL) //if the list is nonempty, make it empty destroyList(); if (otherList.first == NULL) //otherList is empty { this->first = NULL; this->last = NULL; this->count = 0; } else { current = otherList.first; //current points to the //list to be copied this->count = otherList.count; //copy the this->first node this->first = new nodeType ; //create the node this->first->info = current->info; //copy the info this->first->link = NULL; //set the link field of the node to NULL this->last = this->first; //make this->last point to the this->first node current = current->link; //make current point to the next // node //copy the remaining list while (current != NULL) { newNode = new nodeType ; //create a node newNode->info = current->info; //copy the info newNode->link = NULL; //set the link of newNode to NULL this->last->link = newNode; //attach newNode after this->last this->last = newNode; //make this->last point to the actual this->last /ode current = current->link; //make current point to the /ext node } //end while } //end else } //end copyList template linkedListType ::~linkedListType() //destructor { destroyList(); } template linkedListType ::linkedListType(const linkedListType & otherList) { this->first = NULL; copyList(otherList); } //end copy constructor //overload the assignment operator template const linkedListType & linkedListType ::operator = (const linkedListType & otherList) { if (this != &otherList) //avoid self-copy { copyList(otherList); } //end else return *this; } #endif#include #include "unorderedLinkedList.h" using namespace std; int main() { unorderedLinkedList L,L1,L2; L.insertlast(2); L.insertlast(1); L.insertlast(3); L.insertlast(4); L.insertlast(5); L.insertlast(3); L.insertlast(0); cout Part 3: Redo Part 1 on the linked ListType.h. You cannot use any predefined member function. All your modifications should be performed inside the header file linked ListType.h that is attached with this assignment. After performing the modifications, you should run the file memberLinkedList.cpp (attached with this assignment) without modifying it without any problems and you should get the following output: List L before LincrementByConstant(3) contains: 2134530 List Lafter LincrementByConstant(3) contains: 5467863 List L before L.sortEach2('a') contains: 2134530 List Lafter L.sortEach2 l'a") contains: 123 4350 List L before L.sortEach2('d') contains: 2134530 List Lafter L.sortEach21'd') contains: 2143530 List L before L.duplicate Rremove(3) contains: 2134530 List Lafter L.duplicate Rremove(3) contains: 344553 List L before L.split(3,L1, L2) contains: 2134530 List Lafter L.split(3, L1, L2) contains: 2134530 List L1 after L.split(3,L1,L2) contains: 210 List L2 after L.split(3,L1,L2) contains: 3453 Part 3: Redo Part 1 on the linked ListType.h. You cannot use any predefined member function. All your modifications should be performed inside the header file linked ListType.h that is attached with this assignment. After performing the modifications, you should run the file memberLinkedList.cpp (attached with this assignment) without modifying it without any problems and you should get the following output: List L before LincrementByConstant(3) contains: 2134530 List Lafter LincrementByConstant(3) contains: 5467863 List L before L.sortEach2('a') contains: 2134530 List Lafter L.sortEach2 l'a") contains: 123 4350 List L before L.sortEach2('d') contains: 2134530 List Lafter L.sortEach21'd') contains: 2143530 List L before L.duplicate Rremove(3) contains: 2134530 List Lafter L.duplicate Rremove(3) contains: 344553 List L before L.split(3,L1, L2) contains: 2134530 List Lafter L.split(3, L1, L2) contains: 2134530 List L1 after L.split(3,L1,L2) contains: 210 List L2 after L.split(3,L1,L2) contains: 3453 Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
