Completed ArrayDataEngine
+- ArrayDataEngine.c +- PA05_Main
This commit is contained in:
parent
66c7eeef25
commit
4acd4386fe
2 changed files with 42 additions and 5 deletions
|
|
@ -61,10 +61,19 @@ Dependencies: privateCheckForResize, deepCopyData
|
|||
*/
|
||||
void copyDataList( StateArrayType *dest, const StateArrayType src )
|
||||
{
|
||||
// check for resize
|
||||
// check to see if the array dest capacity is less than source
|
||||
int copyIterator;
|
||||
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
|
||||
// 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
|
||||
}
|
||||
|
||||
|
|
@ -181,11 +190,17 @@ bool getItemAtIndex( StateDataType *returnVal,
|
|||
const StateArrayType stateData, int listIndex )
|
||||
{
|
||||
// check stateData size against list index
|
||||
if(listIndex < getListSize(stateData) && listIndex >=0)
|
||||
{
|
||||
// copy data into returnVal
|
||||
deepCopyData(returnVal, stateData.array[listIndex]);
|
||||
// return true
|
||||
return true;
|
||||
}
|
||||
// otherwise,
|
||||
// use setItemToEmpty for returnVal
|
||||
// return false (TEMP)
|
||||
setItemToEmpty(returnVal);
|
||||
// return false
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -223,12 +238,24 @@ Dependencies: checkForResize
|
|||
bool insertItemAtIndex( StateArrayType *stateData,
|
||||
StateDataType toBeInserted, int insertIndex )
|
||||
{
|
||||
int insertIterator;
|
||||
// check for resize
|
||||
privateCheckForResize(stateData);
|
||||
// check to see if index is within size
|
||||
if(insertIndex < getListSize(*stateData) && insertIndex >= 0)
|
||||
{
|
||||
// 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
|
||||
stateData->array[insertIndex] = toBeInserted;
|
||||
// return true
|
||||
// return false (TEMP)
|
||||
return true;
|
||||
}
|
||||
// return false
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -336,10 +363,20 @@ Dependencies: none
|
|||
bool removeItemAtIndex( StateArrayType *stateData,
|
||||
StateDataType *removedItem, int removeIndex )
|
||||
{
|
||||
int removalIterator;
|
||||
// check to see if index is within size
|
||||
if(removeIndex < getListSize(*stateData) && removeIndex >= 0)
|
||||
{
|
||||
// for loop (iterate through list starting at the index)
|
||||
for(removalIterator = removeIndex; removalIterator < getListSize(*stateData); removalIterator++)
|
||||
{
|
||||
// shift the next element to current element.
|
||||
stateData->array[removalIterator] = stateData->array[removalIterator + 1];
|
||||
}
|
||||
// return true once done
|
||||
return true;
|
||||
}
|
||||
|
||||
// return false if item not removable?
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue