Created most of the Array Engine, sanity checking.
+- ArrayDataEngine.c ++ PA05_Main
This commit is contained in:
parent
e0aadd2db6
commit
66c7eeef25
2 changed files with 118 additions and 6 deletions
|
|
@ -37,6 +37,10 @@ Dependencies: free
|
|||
*/
|
||||
StateArrayType *clearDataStructure( StateArrayType *arrayPtr )
|
||||
{
|
||||
// free the array from memory
|
||||
free(arrayPtr->array);
|
||||
// free the struct from memory
|
||||
free(arrayPtr);
|
||||
// return NULL
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -57,6 +61,10 @@ 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
|
||||
// if it is, then size the dest to what source was
|
||||
// copy the data from source to dest using deepCopy
|
||||
// no return, void
|
||||
}
|
||||
|
||||
|
|
@ -73,8 +81,15 @@ Dependencies: malloc, sizeof (C keyword)
|
|||
*/
|
||||
StateArrayType *createDataStructure( int initialCapacity )
|
||||
{
|
||||
// return stateArrayType
|
||||
return NULL;
|
||||
StateArrayType *stateDataStructure;
|
||||
// initialize data structure
|
||||
stateDataStructure = malloc(sizeof(StateArrayType));
|
||||
stateDataStructure->size = 0;
|
||||
stateDataStructure->capacity = initialCapacity;
|
||||
// initialize array for data structure
|
||||
stateDataStructure->array = malloc(sizeof(StateDataType) * initialCapacity);
|
||||
// return data structure
|
||||
return stateDataStructure;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -89,6 +104,13 @@ Dependencies: privateCopyString
|
|||
*/
|
||||
void deepCopyData( StateDataType *dest, const StateDataType src )
|
||||
{
|
||||
// *dest.population = src.population (for each piece)
|
||||
dest->population = src.population;
|
||||
dest->growth = src.growth;
|
||||
dest->majority = src.majority;
|
||||
// privateCopyString for the string
|
||||
// privateCopyString(*dest.name, src.name)
|
||||
privateCopyString(dest->name, src.name);
|
||||
// no return, void
|
||||
}
|
||||
|
||||
|
|
@ -107,6 +129,36 @@ Dependencies: printf, listIsEmpty
|
|||
*/
|
||||
void displayData( const StateArrayType stateData, const char *subTitle )
|
||||
{
|
||||
int displayIterator;
|
||||
// check to see if the list isn't empty
|
||||
if(!listIsEmpty(stateData))
|
||||
{
|
||||
// if that is true, then display:
|
||||
// print Display Data
|
||||
printf("Display Data - ");
|
||||
// print subtitle (and new line)
|
||||
printf("%s\n", subTitle);
|
||||
// for loop (iterates through the array data)
|
||||
for(displayIterator = 0; displayIterator < stateData.size; displayIterator++)
|
||||
{
|
||||
// print Name,
|
||||
printf("%s, ", stateData.array[displayIterator].name);
|
||||
// print Population,
|
||||
printf("%d, ", stateData.array[displayIterator].population);
|
||||
// print Growth,
|
||||
printf("%f, ", stateData.array[displayIterator].growth);
|
||||
// print Majority
|
||||
printf("%c\n", stateData.array[displayIterator].majority);
|
||||
// print newline (included above)
|
||||
}
|
||||
// end for loop
|
||||
}
|
||||
else
|
||||
{
|
||||
// otherwise, display:
|
||||
// print Data Not Found
|
||||
printf("Data not found - Display aborted\n");
|
||||
}
|
||||
// no return, void
|
||||
}
|
||||
|
||||
|
|
@ -128,6 +180,11 @@ Dependencies: deepCopyData, setItemToEmpty
|
|||
bool getItemAtIndex( StateDataType *returnVal,
|
||||
const StateArrayType stateData, int listIndex )
|
||||
{
|
||||
// check stateData size against list index
|
||||
// copy data into returnVal
|
||||
// return true
|
||||
// otherwise,
|
||||
// use setItemToEmpty for returnVal
|
||||
// return false (TEMP)
|
||||
return false;
|
||||
}
|
||||
|
|
@ -144,8 +201,8 @@ Dependencies: none
|
|||
*/
|
||||
int getListSize( const StateArrayType stateData )
|
||||
{
|
||||
// return 0 (TEMP)
|
||||
return 0;
|
||||
// return stateData.size
|
||||
return stateData.size;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -166,7 +223,13 @@ Dependencies: checkForResize
|
|||
bool insertItemAtIndex( StateArrayType *stateData,
|
||||
StateDataType toBeInserted, int insertIndex )
|
||||
{
|
||||
// check for resize
|
||||
// check to see if index is within size
|
||||
// shift elements right of index to right
|
||||
// insert element at index
|
||||
// return true
|
||||
// return false (TEMP)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -181,7 +244,14 @@ Dependencies: none
|
|||
*/
|
||||
bool listIsEmpty( const StateArrayType array )
|
||||
{
|
||||
// return false (TEMP)
|
||||
// check to see if size is equal to 0
|
||||
if(array.size == 0)
|
||||
{
|
||||
// return true since array empty
|
||||
return true;
|
||||
}
|
||||
// return false if not empty
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -200,6 +270,26 @@ Dependencies: malloc, sizeof (C keyword), deepCopyData, free
|
|||
*/
|
||||
void privateCheckForResize( StateArrayType *stateData )
|
||||
{
|
||||
StateDataType *biggerStateArray;
|
||||
int resizeIterator;
|
||||
// do a check for size equal to capacity
|
||||
if(stateData->size == stateData->capacity)
|
||||
{
|
||||
// 'create' bigger array
|
||||
stateData->capacity = stateData->capacity * 2;
|
||||
// allocate the bigger array
|
||||
biggerStateArray = (StateDataType *)malloc(sizeof(StateDataType) * stateData->capacity);
|
||||
// copy the new array stuff into the old space, use loop
|
||||
for(resizeIterator = 0; resizeIterator < stateData->size; resizeIterator++)
|
||||
{
|
||||
// use deep copy to copy the pieces of smaller array
|
||||
deepCopyData(&biggerStateArray[resizeIterator], stateData->array[resizeIterator]);
|
||||
}
|
||||
// free the old array
|
||||
free(stateData->array);
|
||||
// point the stateArray to the old array
|
||||
stateData->array = biggerStateArray;
|
||||
}
|
||||
// no return, void
|
||||
}
|
||||
|
||||
|
|
@ -215,6 +305,17 @@ Dependencies: none
|
|||
*/
|
||||
void privateCopyString( char *dest, const char *src )
|
||||
{
|
||||
int characterCount = 0;
|
||||
// use a while loop, check for !NULL_CHAR
|
||||
while(src[characterCount] != NULL_CHAR)
|
||||
{
|
||||
// copy the character accessed into dest string
|
||||
dest[characterCount] = src[characterCount];
|
||||
// iterate the number of characters
|
||||
characterCount = characterCount + 1;
|
||||
}
|
||||
// add a NULL_CHAR once done. (destStringIterator + 1)
|
||||
dest[characterCount + 1] = NULL_CHAR;
|
||||
// no return, void
|
||||
}
|
||||
|
||||
|
|
@ -235,7 +336,11 @@ Dependencies: none
|
|||
bool removeItemAtIndex( StateArrayType *stateData,
|
||||
StateDataType *removedItem, int removeIndex )
|
||||
{
|
||||
// return false (TEMP)
|
||||
// check to see if index is within size
|
||||
// for loop (iterate through list starting at the index)
|
||||
// shift the next element to current element.
|
||||
// return true once done
|
||||
// return false if item not removable?
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -253,5 +358,12 @@ Dependencies: none
|
|||
*/
|
||||
void setItemToEmpty( StateDataType *data )
|
||||
{
|
||||
// set the data's name to ""
|
||||
data->name[0] = NULL_CHAR;
|
||||
// set the data's population and growth to 0
|
||||
data->population = 0;
|
||||
data->growth = 0.0;
|
||||
// set the data's majority to 'x'
|
||||
data->majority = 'x';
|
||||
// no return, void
|
||||
}
|
||||
BIN
PA05-1004/PA05_Main
Executable file
BIN
PA05-1004/PA05_Main
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue