Completed ArrayDataEngine

+- ArrayDataEngine.c
+- PA05_Main
This commit is contained in:
Charles Descamps 2023-10-02 19:09:53 -07:00
parent 66c7eeef25
commit 4acd4386fe
2 changed files with 42 additions and 5 deletions

View file

@ -61,10 +61,19 @@ Dependencies: privateCheckForResize, deepCopyData
*/ */
void copyDataList( StateArrayType *dest, const StateArrayType src ) void copyDataList( StateArrayType *dest, const StateArrayType src )
{ {
// check for resize int copyIterator;
// check to see if the array dest capacity is less than source privateCheckForResize(dest);
// check for resize if the destination capacity is less than source
if(dest->capacity == src.capacity)
{
dest->size = src.size;
// if it is, then size the dest to what source was // if it is, then size the dest to what source was
// copy the data from source to dest using deepCopy // copy the data from source to dest using deepCopy
for(copyIterator = 0; copyIterator < src.size; copyIterator++)
{
deepCopyData(&dest->array[copyIterator], src.array[copyIterator]);
}
}
// no return, void // no return, void
} }
@ -181,11 +190,17 @@ bool getItemAtIndex( StateDataType *returnVal,
const StateArrayType stateData, int listIndex ) const StateArrayType stateData, int listIndex )
{ {
// check stateData size against list index // check stateData size against list index
if(listIndex < getListSize(stateData) && listIndex >=0)
{
// copy data into returnVal // copy data into returnVal
deepCopyData(returnVal, stateData.array[listIndex]);
// return true // return true
return true;
}
// otherwise, // otherwise,
// use setItemToEmpty for returnVal // use setItemToEmpty for returnVal
// return false (TEMP) setItemToEmpty(returnVal);
// return false
return false; return false;
} }
@ -223,12 +238,24 @@ Dependencies: checkForResize
bool insertItemAtIndex( StateArrayType *stateData, bool insertItemAtIndex( StateArrayType *stateData,
StateDataType toBeInserted, int insertIndex ) StateDataType toBeInserted, int insertIndex )
{ {
int insertIterator;
// check for resize // check for resize
privateCheckForResize(stateData);
// check to see if index is within size // check to see if index is within size
if(insertIndex < getListSize(*stateData) && insertIndex >= 0)
{
// shift elements right of index to right // shift elements right of index to right
for(insertIterator = insertIndex; insertIterator < getListSize(*stateData); insertIterator++)
{
// put the element into element + 1
stateData->array[insertIterator + 1] = stateData->array[insertIterator];
}
// insert element at index // insert element at index
stateData->array[insertIndex] = toBeInserted;
// return true // return true
// return false (TEMP) return true;
}
// return false
return false; return false;
} }
@ -336,10 +363,20 @@ Dependencies: none
bool removeItemAtIndex( StateArrayType *stateData, bool removeItemAtIndex( StateArrayType *stateData,
StateDataType *removedItem, int removeIndex ) StateDataType *removedItem, int removeIndex )
{ {
int removalIterator;
// check to see if index is within size // check to see if index is within size
if(removeIndex < getListSize(*stateData) && removeIndex >= 0)
{
// for loop (iterate through list starting at the index) // for loop (iterate through list starting at the index)
for(removalIterator = removeIndex; removalIterator < getListSize(*stateData); removalIterator++)
{
// shift the next element to current element. // shift the next element to current element.
stateData->array[removalIterator] = stateData->array[removalIterator + 1];
}
// return true once done // return true once done
return true;
}
// return false if item not removable? // return false if item not removable?
return false; return false;
} }

Binary file not shown.