StateUtilities Implementation
+- StateUtilities.c
This commit is contained in:
parent
91b6fc42d5
commit
7a38272632
2 changed files with 32 additions and 7 deletions
|
|
@ -4,6 +4,9 @@
|
||||||
const int NAME_BLOCK_SIZE = 16;
|
const int NAME_BLOCK_SIZE = 16;
|
||||||
const int POPULATION_BLOCK_SIZE = 12;
|
const int POPULATION_BLOCK_SIZE = 12;
|
||||||
const int GROWTH_BLOCK_SIZE = 10;
|
const int GROWTH_BLOCK_SIZE = 10;
|
||||||
|
// missing constants from assignment file
|
||||||
|
const int ITEM_BLOCK_SIZE = 6;
|
||||||
|
const int MAJORITY_BLOCK_SIZE = 10;
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
|
|
||||||
|
|
@ -29,8 +32,15 @@ bool addElementFromData( StateDataType *stateArr, int *size, int capacity,
|
||||||
const char *stateName, int statePop,
|
const char *stateName, int statePop,
|
||||||
double stateGrowth, char politicalMajority )
|
double stateGrowth, char politicalMajority )
|
||||||
{
|
{
|
||||||
//
|
// check to see if the size will go over the capacity
|
||||||
return NULL;
|
// put in the data to the array
|
||||||
|
// array[*size] = parameter
|
||||||
|
// string is a little different.
|
||||||
|
// use strcpy(array[*size].name, stateName)
|
||||||
|
// increment size (*size = *size + 1)
|
||||||
|
// return true
|
||||||
|
// otherwise, return false.
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -50,8 +60,8 @@ Dependencies: addElementFromData - function uses one code statement
|
||||||
bool addElementFromElement( StateDataType *stateArr, int *size, int capacity,
|
bool addElementFromElement( StateDataType *stateArr, int *size, int capacity,
|
||||||
const StateDataType state )
|
const StateDataType state )
|
||||||
{
|
{
|
||||||
//
|
return addElementFromData(stateArr, size, capacity, state.name,
|
||||||
return NULL;
|
state.population, state.growth, state.majority);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -66,7 +76,7 @@ Dependencies: as needed, including free
|
||||||
*/
|
*/
|
||||||
StateDataType *clearStateArray( StateDataType *array )
|
StateDataType *clearStateArray( StateDataType *array )
|
||||||
{
|
{
|
||||||
//
|
// use free to deallocate the array
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,10 +92,13 @@ Dependencies: as needed
|
||||||
*/
|
*/
|
||||||
void copyArray( StateDataType *dest, const StateDataType *src, int srcSize )
|
void copyArray( StateDataType *dest, const StateDataType *src, int srcSize )
|
||||||
{
|
{
|
||||||
|
// use a for loop to iterate through source array (start at zero, go to srcSize)
|
||||||
|
// copy each element from the array to the new array.
|
||||||
|
// uses deepCopy to do this.
|
||||||
// no return, void
|
// no return, void
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* COMPLETE
|
||||||
Name: createStateArray
|
Name: createStateArray
|
||||||
Process: dynamically allocates array memory
|
Process: dynamically allocates array memory
|
||||||
Function input/parameters: initial capacity (int)
|
Function input/parameters: initial capacity (int)
|
||||||
|
|
@ -97,7 +110,10 @@ Dependencies: as needed, including function malloc and keyword sizeof
|
||||||
*/
|
*/
|
||||||
StateDataType *createStateArray( int initialCapacity )
|
StateDataType *createStateArray( int initialCapacity )
|
||||||
{
|
{
|
||||||
//
|
// define variables (integer, StateDataType)
|
||||||
|
// use malloc to dynamically allocate the array,
|
||||||
|
// use the initialCapacity as the size to multiply by.
|
||||||
|
// return the pointer to the array.
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,6 +130,9 @@ Dependencies: as needed, including strcpy
|
||||||
*/
|
*/
|
||||||
void deepCopy( StateDataType *dest, const StateDataType src )
|
void deepCopy( StateDataType *dest, const StateDataType src )
|
||||||
{
|
{
|
||||||
|
// *dest.population = src.population (for each piece)
|
||||||
|
// strcpy for the string
|
||||||
|
// strcpy(*dest.name, src.name)
|
||||||
// no return, void
|
// no return, void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,6 +212,7 @@ Dependencies: as needed
|
||||||
void runBubbleSortByName( StateDataType *array, int size )
|
void runBubbleSortByName( StateDataType *array, int size )
|
||||||
{
|
{
|
||||||
// no return, void
|
// no return, void
|
||||||
|
// bubble sort the data by name of state
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -271,6 +291,11 @@ 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
|
||||||
|
// use deepCopy to copy out swapped element
|
||||||
|
// use deepCopy to move the other element,
|
||||||
|
// use deepCopy to copy the temp element to the other element
|
||||||
|
// updated the array
|
||||||
// no return, void
|
// no return, void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
BIN
PA02-0913/build/Debug/outDebug
Executable file
BIN
PA02-0913/build/Debug/outDebug
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue