diff --git a/PA05-1004/ArrayDataEngine.c b/PA05-1004/ArrayDataEngine.c index 87041d7..3e726ce 100644 --- a/PA05-1004/ArrayDataEngine.c +++ b/PA05-1004/ArrayDataEngine.c @@ -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) - // shift the next element to current element. + 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; } diff --git a/PA05-1004/PA05_Main b/PA05-1004/PA05_Main index 183f669..62a8033 100755 Binary files a/PA05-1004/PA05_Main and b/PA05-1004/PA05_Main differ