diff --git a/PA02-0913/PA02_Main b/PA02-0913/PA02_Main index 6eadf1b..1a577e4 100755 Binary files a/PA02-0913/PA02_Main and b/PA02-0913/PA02_Main differ diff --git a/PA02-0913/StateUtilities.c b/PA02-0913/StateUtilities.c index 8de4be8..316c8ce 100644 --- a/PA02-0913/StateUtilities.c +++ b/PA02-0913/StateUtilities.c @@ -179,8 +179,10 @@ void displayData( const StateDataType *array, int size, const char *subTitle ) if(size != 0) { printEndline(); + printString("Display Data - "); printString(subTitle); printEndline(); + printEndline(); // create a table // print PIPE character printCharacter(PIPE); @@ -353,13 +355,30 @@ Dependencies: as needed bool removeStateByName( StateDataType *removedElement, StateDataType *array, int *size, const StateDataType searchVal ) { - //bool stateNameFound; - //stateNameFound = findStateByName(removedElement, array, *size, searchVal); - // iterate through array + bool stateNameFound; + int removeCount; + int stateNameFoundFlag = 0; // use the findStateByName to search - // remove the element by copying the next element into last slot until end - // reduce the size by one - // return true + stateNameFound = findStateByName(removedElement, array, *size, searchVal); + // iterate through array + if(stateNameFound) + { + // + for(removeCount = 0; removeCount < *size; removeCount++) + { + if(strcmp(array[removeCount].name, removedElement->name) == 0 || stateNameFoundFlag == 1) + { + // set the flag to signify found value + stateNameFoundFlag = 1; + // remove the element by copying the next element into last slot until end + deepCopy(&array[removeCount], array[removeCount + 1]); + } + } + // reduce the size by one + *size = *size - 1; + // return true + return true; + } // otherwise, return false return false; } @@ -475,9 +494,13 @@ Dependencies: as needed void swapElements( StateDataType *array, int leftIndex, int rightIndex ) { // create StateDataType temp to store swapped element + StateDataType *storeElement; // use deepCopy to copy out swapped element + deepCopy(storeElement, array[leftIndex]); // use deepCopy to move the other element, + deepCopy(&array[leftIndex], array[rightIndex]); // use deepCopy to copy the temp element to the other element + deepCopy(&array[rightIndex], *storeElement); // updated the array // no return, void }