Uploading complete supporting functions
+- PA02_Main +- StateUtilities.c
This commit is contained in:
parent
40cfac158c
commit
a88b49135b
2 changed files with 29 additions and 6 deletions
Binary file not shown.
|
|
@ -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
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue