Question: data structure using c++ please don't use predefined functions when you answer, for ex: void incrementByConstant(arrayListType & L, int num) { for(int i {0}; i
data structure using c++
please don't use predefined functions when you answer, for ex:
void incrementByConstant(arrayListType& L, int num) { for(int i {0}; i dont use removeAt(), insertAt(),insertEnd, retrieveAt(),replaceAt, etc inside implementation of nonmember functions.
#ifndef ARRAY_LIST_TYPE #define ARRAY_LIST_TYPE #include#include using namespace std; // This class specifies the members to implement the basic // properties of array-based lists. template class arrayListType { public: const arrayListType & operator = (const arrayListType & ); //Overloads the assignment operator bool isEmpty() const; bool isFull() const; int listSize() const; int maxListSize() const; void print() const; bool isItemAtEqual(int location,const elemType & item) const; void insertAt(int location,const elemType & insertItem); void insertEnd(const elemType & insertItem); void removeAt(int location); void retrieveAt(int location, elemType & retItem) const; void replaceAt(int location,const elemType & repItem); void clearList(); int seqSearch(const elemType & item) const; void insert(const elemType & insertItem); void remove(const elemType & removeItem); arrayListType(int size = 100); arrayListType(const arrayListType & otherList); //copy constructor ~arrayListType(); //destructor //Deallocates the memory occupied by the array. // added portion start here: --------------------------------------------------------------------------- // declaration for the incrementByConstant function void incrementByConstant(elemType element); // declaration of the sortEach2 function void sortEach2(char c); // declaration of duplicateORremove function void duplicateORremove(elemType element); // and lastly declaration of the split function void split(elemType element, arrayListType & list1, arrayListType & list2); // added portion end here -------------------------------------------------------------------------------- protected: elemType * list; //array to hold the list elements int length; //to store the length of the list int maxSize; //to store the maximum size of the list }; template bool arrayListType ::isEmpty() const { return (length == 0); } template bool arrayListType ::isFull() const { return (length == maxSize); } template int arrayListType ::listSize() const { return length; } template int arrayListType ::maxListSize() const { return maxSize; } template void arrayListType ::print() const { for (int i = 0; i bool arrayListType ::isItemAtEqual(int location, const elemType & item) const { if (location = length){ cerr void arrayListType ::insertAt(int location, const elemType & insertItem) { if (location length) cerr = maxSize) //list is full cerr location; i--) list[i] = list[i - 1]; //move the elements down list[location] = insertItem; //insert the item at the //specified position length++; //increment the length } } //end insertAt template void arrayListType ::insertEnd(const elemType & insertItem) { if (length >= maxSize) //the list is full cerr void arrayListType ::removeAt(int location) { if (location = length) cerr void arrayListType ::retrieveAt(int location, elemType & retItem) const { if (location = length) cerr void arrayListType ::replaceAt(int location, const elemType & repItem) { if (location = length) cerr void arrayListType ::clearList() { length = 0; } //end clearList template arrayListType ::arrayListType(int size) { if (size arrayListType ::~arrayListType() { delete[] list; } template arrayListType ::arrayListType(const arrayListType & otherList) { maxSize = otherList.maxSize; length = otherList.length; list = new elemType[maxSize]; //create the array assert(list != NULL); //terminate if unable to allocate //memory space for (int j = 0; j const arrayListType & arrayListType ::operator = (const arrayListType & otherList) { if (this != & otherList) //avoid self-assignment { delete[] list; maxSize = otherList.maxSize; length = otherList.length; list = new elemType[maxSize]; //create the array assert(list != NULL); //if unable to allocate memory //space, terminate the program for (int i = 0; i int arrayListType ::seqSearch(const elemType & item) const { int loc; bool found = false; for (loc = 0; loc void arrayListType ::insert(const elemType & insertItem) { int loc; if (length == 0) //list is empty list[length++] = insertItem; //insert the item and //increment the length else if (length == maxSize) cerr void arrayListType ::remove(const elemType & removeItem) { int loc; if (length == 0) cerr void arrayListType :: incrementByConstant(elemType element){ // loop through the list and every index increment the value by element for(int i=0;i void arrayListType :: sortEach2(char c){ // if the character is a i.e, ascending if (c=='a'){ // loop through the list incrementing by 2 to see two consecutive elements at a time for(int i=0;i list[i+1]){ // swapping is done using third value temp_value elemType temp_value = list[i]; list[i] = list[i+1]; list[i+1] = temp_value; } } } } // if the character is d (i.e, descending) else if (c=='d'){ // loop through the list and increment by 2 each time to process consecutive elements together for(int i=0;i void arrayListType :: duplicateORremove(elemType element){ // declare another list nlist of max size and make a variable nlist_size which will store its size initialize it to 0 elemType *nlist = new elemType[maxSize]; int nlist_size = 0; // loop through the list till the length and check element for(int i=0;i element){ // add the same element two times in the new list and increment the size nlist_size nlist[nlist_size] = list[i]; nlist_size++; nlist[nlist_size] = list[i]; nlist_size++; } // else if the value is equal to the element and for any thing else avoid that value else if (list[i]==element){ // add the element once increment new list size nlist[nlist_size] = list[i]; nlist_size++; } } // now clear the current list to assign new list in this clearList(); // now copy each value of new list nlist to the current list and increment its length for(int i=0;i void arrayListType ::split(elemType element, arrayListType & list1, arrayListType &list2){ // loop over the length and check every element for(int i=0;i #include//Line 1 #include //Line 2 #include #include "arrayListType.h" //Line using namespace std; //Line 4 int main() //Line 5 { arrayListType L,L1,L2; L.insertEnd(2); L.insertEnd(1); L.insertEnd(3); L.insertEnd(4); L.insertEnd(5); L.insertEnd(3); L.insertEnd(0); cout Part 2: Starting from the arrayListType.h (attached with the assignment), write the specified member function in Part 1 as non-member functions. Not theta for Part 1, we were calling the member functions using the object L. for this part, this object should be passed by reference to the functions with the other needed function parameters. All functions should be added to the arrayListType.h. After performing the needed modifications to arrayListType.h, you should run the file nonmemberArrayList.cpp (attached with this assignment) without modifying it without any problems and you should get the following output: List L before incrementByConstant(L,3) contains: 2134530 List Lafter incrementByConstant(1,3) contains: 5 46 7863 List L before sortEach2(L, 'a') contains: 2134530 List Lafter sortEach 2(L, 'a") contains: 1234350 List L before sortEach2(L,'d') contains: 2134530 List Lafter sortEach 2(L,'d') contains: 2143530 List L before duplicate Orremove(4,3) contains: 2134530 List Lafter duplicate Rremove(L,3) contains: 344553 List L before split(1,3,L1,L2) contains: 2134530 List Lafter split(1,3,L1,L2) contains: 2134530 List L1 after split(1,3,L1,L2) contains: 210 List L2 after split(L,3,L1,L2) contains: 3453 Part 2: Starting from the arrayListType.h (attached with the assignment), write the specified member function in Part 1 as non-member functions. Not theta for Part 1, we were calling the member functions using the object L. for this part, this object should be passed by reference to the functions with the other needed function parameters. All functions should be added to the arrayListType.h. After performing the needed modifications to arrayListType.h, you should run the file nonmemberArrayList.cpp (attached with this assignment) without modifying it without any problems and you should get the following output: List L before incrementByConstant(L,3) contains: 2134530 List Lafter incrementByConstant(1,3) contains: 5 46 7863 List L before sortEach2(L, 'a') contains: 2134530 List Lafter sortEach 2(L, 'a") contains: 1234350 List L before sortEach2(L,'d') contains: 2134530 List Lafter sortEach 2(L,'d') contains: 2143530 List L before duplicate Orremove(4,3) contains: 2134530 List Lafter duplicate Rremove(L,3) contains: 344553 List L before split(1,3,L1,L2) contains: 2134530 List Lafter split(1,3,L1,L2) contains: 2134530 List L1 after split(1,3,L1,L2) contains: 210 List L2 after split(L,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

