Uploading complete supporting functions

+- PA02_Main
+- StateUtilities.c
This commit is contained in:
Charles Descamps 2023-09-11 12:04:51 -07:00
parent 40cfac158c
commit a88b49135b
2 changed files with 29 additions and 6 deletions

Binary file not shown.

View file

@ -179,8 +179,10 @@ void displayData( const StateDataType *array, int size, const char *subTitle )
if(size != 0) if(size != 0)
{ {
printEndline(); printEndline();
printString("Display Data - ");
printString(subTitle); printString(subTitle);
printEndline(); printEndline();
printEndline();
// create a table // create a table
// print PIPE character // print PIPE character
printCharacter(PIPE); printCharacter(PIPE);
@ -353,13 +355,30 @@ Dependencies: as needed
bool removeStateByName( StateDataType *removedElement, bool removeStateByName( StateDataType *removedElement,
StateDataType *array, int *size, const StateDataType searchVal ) StateDataType *array, int *size, const StateDataType searchVal )
{ {
//bool stateNameFound; bool stateNameFound;
//stateNameFound = findStateByName(removedElement, array, *size, searchVal); int removeCount;
// iterate through array int stateNameFoundFlag = 0;
// use the findStateByName to search // use the findStateByName to search
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 // remove the element by copying the next element into last slot until end
deepCopy(&array[removeCount], array[removeCount + 1]);
}
}
// reduce the size by one // reduce the size by one
*size = *size - 1;
// return true // return true
return true;
}
// otherwise, return false // otherwise, return false
return false; return false;
} }
@ -475,9 +494,13 @@ Dependencies: as needed
void swapElements( StateDataType *array, int leftIndex, int rightIndex ) void swapElements( StateDataType *array, int leftIndex, int rightIndex )
{ {
// create StateDataType temp to store swapped element // create StateDataType temp to store swapped element
StateDataType *storeElement;
// use deepCopy to copy out swapped element // use deepCopy to copy out swapped element
deepCopy(storeElement, array[leftIndex]);
// use deepCopy to move the other element, // use deepCopy to move the other element,
deepCopy(&array[leftIndex], array[rightIndex]);
// use deepCopy to copy the temp element to the other element // use deepCopy to copy the temp element to the other element
deepCopy(&array[rightIndex], *storeElement);
// updated the array // updated the array
// no return, void // no return, void
} }