Question: Objective: Finish the PlaceValue and ExpandArray functions By doing so you would have a basic library for dynamic arrays Steps: 1) Finish the ExpandArray function

Objective:

Finish the PlaceValue and ExpandArray functions

By doing so you would have a basic library for dynamic arrays

Steps:

1) Finish the ExpandArray function Allocate space for the new array using either malloc or calloc

Save the address this returns to a temporary pointer

Copy data from the OLD pointer to the NEW pointer

Old pointer is in the data struct, new pointer is what you just created

You can use memcpy or a for loop

Free the OLD pointer within the struct

Update the structs pointer and max size variable

2) Finish the PlaceValue function

Place the value at the next available space in the array using effectiveSize (all within the struct)

Increase effectiveSize by 1

Check if effectiveSize == maxSize

If so, call the ExpandArray function

If you want, print a message that you are expanding the array

3) In the main function

Call PlaceValue at least 10 times with 10 different values.

Call PrintArray()

In the attached example I chose to fill the array with 0-9 values.

Objective: Finish the PlaceValue and ExpandArray functions By doing so you would

Expanding array from 5 to 10 Expanding array from 10 to 20 0 1 2 3 4 5689 Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!