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.
Expanding array from 5 to 10 Expanding array from 10 to 20 0 1 2 3 4 5689 Press any key to continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started