Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IN C++ #include #include #include #include #include #include using namespace std; class List{ private : int *array; int maxSize; int endOfArray; public : List(){}

image text in transcribed

CODE IN C++

#include

#include

#include

#include

#include

#include

using namespace std;

class List{

private:

int *array;

int maxSize;

int endOfArray;

public:

List(){}

List(int size){

maxSize = size;

array = new int[maxSize];

endOfArray = -1;

}

void SetUp(int size){

maxSize = size;

array = new int[maxSize];

endOfArray = -1;

}

bool isEmpty(){

if (endOfArray == -1)

return true;

return false;

}

void resize(int s){

int *tempArray = array;

array = new int[s];

for (int index = 0; index

array[index] = tempArray[index];

}

maxSize = s;

delete[] tempArray;

}

void insertAtIndex(int insertIndex, int data){

// if the user enters an invalid insertIndex, the element is

// appended to the array, after the current last element

if (insertIndex > endOfArray+1 || insertIndex

insertIndex = endOfArray+1;

if (endOfArray == maxSize-1){

resize(maxSize+1);

//resize(2*maxSize);

}

for (int index = endOfArray; index >= insertIndex; index--)

array[index+1] = array[index];

array[insertIndex] = data;

endOfArray++;

}

void deleteList(){

delete[] array;

}

void PrintList(){

for (int index = 0; index

cout

cout

}

};

int main(){

using namespace std::chrono;

srand(time(NULL));

int numLists;

cout

cin >> numLists;

int listSize;

cout

cin >> listSize;

int maxValue;

cout

cin >> maxValue;

// Create an array of numLists, each of size listSize

// Setup/Initialize the member variables of each of the List objects in the array

// Populate each List object of the array with values ranging from 1 to maxValue

// Every time an integer is to be inserted to a List object, the integer is inserted

// at index 0 of the List object.

// Print the contents of each List object

// Delete all the List objects and clear the space allocated for the array of List // objects

system("pause");

return 0;

}

Due by: Feb. 9th, 11.59 PM In this assignment, you are provided the code for a List class that has the functions to setup/initialize the list, insert to the list, delete from the list and etc. Your task is to extend the main function of the code to create an array of List objects and insert elements (randomly generated integers) to each of these List objects and print the contents of the List objects. The base address of the array of List objects is stored in a pointer named 'listArray' of type List. The number of List objects (identified using the variable 'numLists) to be stored in the array is 5. The number of integer elements per List object (identified using the variable 'listSize') is 10. Each List object is to be filled up with randomly generated integers in the range of 1 ... maxValue, where max Value = 50. Each insertion has to be made at index 0 of the List object. For example, if the random integers 23 45 12 34 49 are to be inserted to a List object, the contents of the List object after each insertion (at index 0) looks like this: 22 23 45 23 12 45 23 34 12 45 23 49 34 12 45 23 After filling up all the List objects, print the contents of each of them. After printing the contents of all the List objects, delete each List object and eventually clear up the space for the array of List objects. Submission: 1 - 75 pts) The entire .cpp file with the main function implemented as indicated. 2) A PDF document containing the following: (a - 20 pts) With the insertions occurring at index 0 of a List, determine the time complexity of inserting 'n' elements to every List object in an array of 'm' List objects. Show the pseudo code for the insertion step and analyze the time complexity. (b - 5 pts) A screenshot of the execution of your code. Due by: Feb. 9th, 11.59 PM In this assignment, you are provided the code for a List class that has the functions to setup/initialize the list, insert to the list, delete from the list and etc. Your task is to extend the main function of the code to create an array of List objects and insert elements (randomly generated integers) to each of these List objects and print the contents of the List objects. The base address of the array of List objects is stored in a pointer named 'listArray' of type List. The number of List objects (identified using the variable 'numLists) to be stored in the array is 5. The number of integer elements per List object (identified using the variable 'listSize') is 10. Each List object is to be filled up with randomly generated integers in the range of 1 ... maxValue, where max Value = 50. Each insertion has to be made at index 0 of the List object. For example, if the random integers 23 45 12 34 49 are to be inserted to a List object, the contents of the List object after each insertion (at index 0) looks like this: 22 23 45 23 12 45 23 34 12 45 23 49 34 12 45 23 After filling up all the List objects, print the contents of each of them. After printing the contents of all the List objects, delete each List object and eventually clear up the space for the array of List objects. Submission: 1 - 75 pts) The entire .cpp file with the main function implemented as indicated. 2) A PDF document containing the following: (a - 20 pts) With the insertions occurring at index 0 of a List, determine the time complexity of inserting 'n' elements to every List object in an array of 'm' List objects. Show the pseudo code for the insertion step and analyze the time complexity. (b - 5 pts) A screenshot of the execution of your code

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

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions