Question: / * * dataStructure.c * * Provides a bound - checked data structure made of an array of integers * in which duplicated elements are
dataStructure.c
Provides a boundchecked data structure made of an array of integers
in which duplicated elements are allowed.
The interface of this data structure includes several utility
functions that operate on this array of integers as well as
file io functions: saving into and loading from json files.
Do not change the dataStructure.h file.
Author: RV AL
Modified Date: July
#include for malloc and for rand
#include for file io calls
#include for time
#include for strlen
#include "dataStructure.h
Description: Creates a new intArrayt data structure
with initial array size "size".
If successful ie memory allocation succeeds
returns a pointer to a newlyallocated intArrayt
If unsuccessful, returns a NULL pointer.
Time Efficiency: O
intArrayt intArraycreate unsigned int size
Allocate memory on the heap for intArrayt struct
intArrayt ia malloc sizeof intArrayt ;
if ia NULL
Set its field "size"
iasize size;
Allocate memory on the heap for array
iadata malloc size sizeofint;
if iadata NULL
free ia ;
ia NULL;
else
Set its field "elementCount" to zero empty array
iaelementCount ;
return ia;
Description: Frees all memory allocated for ia
If the pointer ia is NULL, it does nothing.
If the pointer iadata" is NULL, it does not
attempt to free it Returns INTARROK
Time Efficiency: O
intArrayResultt intArraydestroy intArrayt ia
If heap memory has been allocated for intArrayt struct
if ia NULL
If heap memory has been allocated for array
if iadata NULL
then free it
free iadata ;
iadata NULL;
then free it
free ia ;
ia NULL;
return INTARROK;
Description: Appends "newElement" and returns INTARROK
If "newElement" cannot be appended, leaves the
data structure unmodified and returns INTARRERROR.
If ia is NULL, returns INTARRBADPARAM.
Time efficiency: O
intArrayResultt intArrayappend intArrayt ia int newElement
Function Stub
This stub is to be removed when you have successfully implemented this function.
printf "Calling intArrayappend with the parameter newElement d
newElement ;
return INTARROK; You are free to modify this return statement.
Description: Removes the element at "indexToBeRemoved" in the data structure
and returns INTARROK If the data structure was initially sorted,
it does not remain sorted after removing the element at "indexToBeRemoved".
If ia is NULL or "indexToBeRemoved" is out of bounds, returns INTARRBADPARAM.
Time efficiency: O
intArrayResultt intArrayremove intArrayt ia unsigned int indexToBeRemoved
Function Stub
This stub is to be removed when you have successfully implemented this function.
printf "Calling intArrayremove with the parameter indexToBeRemoved u
indexToBeRemoved ;
return INTARROK; You are free to modify this return statement.
Description: Modifies
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
