From b7cb3dc9e0e9bf3b3b4273f9246c7f72197b3d90 Mon Sep 17 00:00:00 2001 From: cdez Date: Tue, 17 Oct 2023 20:48:30 -0700 Subject: [PATCH] Got close to finishing ++ IteratorUtility.c ++ LLDataEngine.c ++ QueueUtility.c ++ StackUtility.c +- PA06_Main.c +- Makefile for PA06 --- PA06-1018/IteratorUtility.c | 213 ++++++++++++++++++++ PA06-1018/LLDataEngine.c | 385 ++++++++++++++++++++++++++++++++++++ PA06-1018/Makefile | 24 +-- PA06-1018/PA06_Main | Bin 0 -> 33632 bytes PA06-1018/PA06_Main.c | 154 ++++++++------- PA06-1018/QueueUtility.c | 106 ++++++++++ PA06-1018/QueueUtility.h | 2 +- PA06-1018/StackUtility.c | 103 ++++++++++ 8 files changed, 899 insertions(+), 88 deletions(-) create mode 100644 PA06-1018/IteratorUtility.c create mode 100644 PA06-1018/LLDataEngine.c create mode 100755 PA06-1018/PA06_Main create mode 100644 PA06-1018/QueueUtility.c create mode 100644 PA06-1018/StackUtility.c diff --git a/PA06-1018/IteratorUtility.c b/PA06-1018/IteratorUtility.c new file mode 100644 index 0000000..beeddf5 --- /dev/null +++ b/PA06-1018/IteratorUtility.c @@ -0,0 +1,213 @@ +// header files +#include "IteratorUtility.h" + +/* Data Structures +typedef struct IteratorStruct + { + StateArrayType *iterData; + + int currentIndex; + } IteratorType; +Data Structures */ + +// function implementation + +/* +Name: clearIterator +Process: clears the StateDataType sub-structure, and then the IteratorType +Function input/parameters: pointer to IteratorType (IteratorType *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: clearDataStructure, free +*/ +IteratorType *clearIterator( IteratorType *iterator ) +{ + // clear the encapsulated data structure + clearDataStructure(iterator->iterData); + // clear the rest of the data structure + free(iterator); + // return NULL + return NULL; +} + +/* +Name: createIterator +Process: initializes the IteratorType, + and then the StateDataType sub-structure +Function input/parameters: initial capacity (int) +Function output/parameters: none +Function output/returned: pointer to initialized IteratorType (IteratorType *) +Device input/---: none +Device output/---: none +Dependencies: malloc, createDataStructure +*/ +IteratorType *createIterator( int initialCapacity ) +{ + IteratorType *iteratorDataStructure; + // create the entire data structure + iteratorDataStructure = malloc(sizeof(IteratorType)); + iteratorDataStructure->currentIndex = 0; + // create the encapsulated data structure + iteratorDataStructure->iterData = createDataStructure(initialCapacity); + // return IteratorType + return iteratorDataStructure; +} + +/* +Name: getFirst +Process: gets first value in iterator, returns true, + returns false otherwise +Function input/parameters: pointer to IteratorType (IteratorType *) +Function output/parameters: return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex +*/ +bool getFirst( IteratorType *iterator, StateDataType *returned ) +{ + // set currentIndex to 0 + iterator->currentIndex = 0; + // return function true/false if value possible + return getItemAtIndex(returned, *iterator->iterData, iterator->currentIndex); +} + +/* +Name: getLast +Process: gets last value in iterator, returns true, + returns false otherwise +Function input/parameters: pointer to IteratorType (IteratorType *) +Function output/parameters: return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex, getListSize +*/ +bool getLast( IteratorType *iterator, StateDataType *returned ) +{ + // set currentIndex to getListSize + iterator->currentIndex = getListSize(*iterator->iterData); + // return function to see if possible + return getItemAtIndex(returned, *iterator->iterData, iterator->currentIndex); +} + +/* +Name: getNext +Process: gets next value in iterator if available, returns true, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to IteratorType (IteratorType *) +Function output/parameters: return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex, getListSize +*/ +bool getNext( IteratorType *iterator, StateDataType *returned ) +{ + // check to see if the currentIndex value is not size. + if(iterator->currentIndex != getListSize(*iterator->iterData)) + { + iterator->currentIndex = iterator->currentIndex + 1; + return getItemAtIndex(returned, *iterator->iterData, + iterator->currentIndex); + } + // return false + return false; +} + +/* +Name: getPrevious +Process: gets previous value in iterator if available, returns true, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to IteratorType (IteratorType *) +Function output/parameters: return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex +*/ +bool getPrevious( IteratorType *iterator, StateDataType *returned ) +{ + // check to see if the currentIndex value is not zero. + if(iterator->currentIndex != 0) + { + iterator->currentIndex = iterator->currentIndex - 1; + return getItemAtIndex(returned, *iterator->iterData, + iterator->currentIndex); + } + // return false + return false; +} + +/* +Name: insertAfterCurrentIndex +Process: inserts value immediately after currentIndex, if possible, returns true, + otherwise, returns false +Function input/parameters: pointer to IteratorType (IteratorType *), + value to be inserted (const StateDataType) +Function output/parameters: none +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: insertItemAtIndex, getListSize +*/ +bool insertAfterCurrentIndex( IteratorType *iterator, + const StateDataType toBeInserted ) +{ + // return function true/false based on possibility + return insertItemAtIndex(iterator->iterData, toBeInserted, + iterator->currentIndex + 1); +} + +/* +Name: insertAtCurrentIndex +Process: inserts value at currentIndex, if possible, returns true + otherwise, returns false +Function input/parameters: pointer to IteratorType (IteratorType *), + value to be inserted (const StateDataType) +Function output/parameters: none +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: insertItemAtIndex +*/ +bool insertAtCurrentIndex( IteratorType *iterator, + const StateDataType toBeInserted ) +{ + // return true/false based on if the function deems worthy + return insertItemAtIndex(iterator->iterData, toBeInserted, + iterator->currentIndex); +} + +/* +Name: removeAtCurrentIndex +Process: removes value at current index if possible, returns true, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to IteratorType (IteratorType *), + value to be remove (StateDataType *) +Function output/parameters: pointer to updated IteratorType (IteratorType *), + pointer to item removed (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: removeItemAtIndex, getListSize +*/ +bool removeAtCurrentIndex( IteratorType *iterator, StateDataType *removedItem ) +{ + // need to check if the last element is being removed + if(iterator->currentIndex == getListSize(*iterator->iterData)) + { + // move the currentIndex back one, + // return removeItemAtIndex with currentIndex + 1 + iterator->currentIndex = iterator->currentIndex - 1; + return removeItemAtIndex(iterator->iterData, removedItem, + iterator->currentIndex + 1); + // gives the effect like it removed, + // but doesn't screw up the rest of the program. + } + // otherwise, remove the item + return removeItemAtIndex(iterator->iterData, removedItem, + iterator->currentIndex); +} \ No newline at end of file diff --git a/PA06-1018/LLDataEngine.c b/PA06-1018/LLDataEngine.c new file mode 100644 index 0000000..21c4f1b --- /dev/null +++ b/PA06-1018/LLDataEngine.c @@ -0,0 +1,385 @@ +// header files +#include "LLDataEngine.h" + +/* Data Structures +typedef struct StateDataStruct + { + char name[ STD_STR_LEN ]; + int population; + double growth; + char majority; + struct StateDataStruct *nextPtr; + } StateDataType; + +typedef struct StateLLStruct + { + StateDataType *headPtr; + } StateLLType; + Data Structures */ + +// function implementations + +/* +Name: clearDataStructure +Process: deallocates memory for the linked list data structure + and encapsulated state data using helper function, + returns NULL to calling function +Function input/parameters: pointer to state linked list array (StateLLType *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: free, clearDataStructureHelper +*/ +StateLLType *clearDataStructure( StateLLType *llPtr ) +{ + // call clearDataStructureHelper with headPtr + privateClearDataStructureHelper(llPtr->headPtr); + // free the headPtr + free(llPtr); + // return NULL + return NULL; +} + +/* +Name: copyDataList +Process: deallocates destination linked list nodes if it is not empty, + then if source list is not empty, + copies all nodes from source list to destination list, + if source list is empty, copied list will also be configured as empty +Function input/parameters: pointer to source state data linked list type + (const StateDataType *) +Function output/parameters: pointer to destination state data array type + (StateLLType *) +Function output/returned: none +Device input/---: none +Device output/---: none +Dependencies: clearDataStructureHelper, privateCreateNodeFromNode +*/ +void copyDataList( StateLLType *dest, const StateLLType *src ) +{ + // no return, void +} + +/* +Name: createDataStructure +Process: dynamically creates instance of state linked list type + along with initializing the linked list within +Function input/parameters: none +Function output/parameters: none +Function output/returned: pointer to state linked list type (StateLLType *) +Device input/---: none +Device output/---: none +Dependencies: malloc, sizeof (C keyword) +*/ +StateLLType *createDataStructure() +{ + // allocate and create StateLLType using malloc and size of + StateLLType *dataStruct; + dataStruct = malloc(sizeof(StateLLType)); + // set the head pointer to null + dataStruct->headPtr = NULL; + // return StateLLType + return dataStruct; +} + +/* +Name: deepCopyData +Process: copies all members of a StateDataType node into another one +Function input/parameters: state data type item (const StateDataType *) +Function output/parameters: pointer to state data item (StateDataType *) +Function output/returned: none +Device input/---: none +Dependencies: privateCopyString +Device output/---: none +*/ +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 +} + +/* +Name: displayData +Process: displays comma-delimited data items in linked list + if linked list is not empty, + otherwise displays "Data not found - Display aborted", + allows for subtitle to be added to "Display Data - " +Function input/parameters: state linked list type (const StateLLType), + subtitle (const char *) +Function output/parameters: none +Function output/returned: none +Device input/---: none +Device output/monitor: data displayed as specified +Dependencies: printf, listIsEmpty +*/ +void displayData( const StateLLType stateData, const char *subTitle ) +{ + // create a working pointer + StateDataType *currentPtr = stateData.headPtr; + // check to see if the list is not empty + if(!listIsEmpty(stateData)) + { + printf("Display Data - "); + printf("%s\n", subTitle); + // while through the linked list + // get the data out of the first node + printf("%s, ", currentPtr->name); + printf("%d, ", currentPtr->population); + printf("%f, ", currentPtr->growth); + printf("%c\n", currentPtr->majority); + while(currentPtr != NULL) + { + // move the pointer + currentPtr = currentPtr->nextPtr; + // get the data out of the current node + printf("%s, ", currentPtr->name); + printf("%d, ", currentPtr->population); + printf("%f, ", currentPtr->growth); + printf("%c\n", currentPtr->majority); + } + } + else + { + // otherwise, display: + // print Data Not Found + printf("Data not found - Display aborted\n"); + } + // no return, void +} + +/* +Name: getItemAtIndex +Process: checks for index within bounds, + acquires and returns the value as a parameter, + and returns true, + otherwise sets data in parameter to empty and returns false +Function input/parameters: state array type (const StateLLType), + list index (int) +Function output/parameters: value if found, + otherwise, value set to empty (StateDataType *) +Function output/returned: Boolean result of operation (bool) +Device input/---: none +Device output/---: none +Dependencies: deepCopyData, setItemToEmpty +*/ +bool getItemAtIndex( StateDataType *returnVal, + const StateLLType stateData, int listIndex ) +{ + // return false (temp) + return false; +} + +/* +Name: getListSize +Process: calculates the linked list size +Function input/parameters: state array type (const StateLLType) +Function output/parameters: none +Function output/returned: size of the list (int) +Device input/---: none +Device output/---: none +Dependencies: none +*/ +int getListSize( const StateLLType stateData ) +{ + int listCounter = 0; + StateDataType *currentPtr = stateData.headPtr; + // check to see if the headPtr + // while through the linked list. count up if next not null. + while(currentPtr != NULL) + { + // listCounter increment + listCounter = listCounter + 1; + // move the pointer + currentPtr = currentPtr->nextPtr; + } + // return listCounter + return listCounter; +} + +/* +Name: insertItemAtIndex +Process: checks for index in bounds, inserts item at index, returns true, + if index not in bounds, returns false, + must also insert item at index = size to all for appending data +Function input/parameters: pointer to state array type (StateLLType *), + StateDataType item to insert (const StateDataType), + index for insertion (int) +Function output/parameters: updated pointer to state array type + (StateLLType *) +Function output/returned: Boolean result of specified process (bool) +Device input/---: none +Device output/---: none +Dependencies: privateCreateNodeFromNode +*/ +bool insertItemAtIndex( StateLLType *stateData, + StateDataType toBeInserted, int insertIndex ) +{ + // return false (temp) + return false; +} + +/* +Name: listIsEmpty +Process: returns true if list is empty, false otherwise +Function input/parameters: state linked list type (const StateLLType) +Function output/parameters: none +Function output/returned: Boolean result of test as specified (bool) +Device input/---: none +Device output/---: none +Dependencies: none +*/ +bool listIsEmpty( const StateLLType array ) +{ + // return the check of headPtr == null + return array.headPtr == NULL; +} + +/* +Name: privateClearDataStructureHelper +Process: recursively iterates through linked list, + removing nodes from bottom to top +Function input/parameters: pointer to state data linked list (StateDataType *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: free, clearDataStructureHelper (recursively) +*/ +StateDataType *privateClearDataStructureHelper( StateDataType *nodePtr ) +{ + // check if node's nextPtr not null + if(nodePtr->nextPtr != NULL) + { + // if it is not null, call the next recursion. + nodePtr->nextPtr = privateClearDataStructureHelper(nodePtr->nextPtr); + } + // free the node using free + free(nodePtr); + // return NULL + return NULL; +} + +/* +Name: privateCreateNodeFromData +Process: creates linked list node provided member data +Function input/parameters: name (const char *), population (int), + growth (double), majority (char) +Function output/parameters: none +Function output/returned: pointer to created node (StateDataType *) +Device input/---: none +Device output/---: none +Dependencies: malloc, privateCopyString, keyword sizeof +*/ +StateDataType *privateCreateNodeFromData( const char *inName, + int inPop, double inGrowth, + char inMajority ) +{ + // allocate node memory using malloc and size of + StateDataType *workingNode; + workingNode = malloc(sizeof(StateDataType)); + // copy string into node + privateCopyString(workingNode->name, inName); + // copy other data pieces into node + workingNode->population = inPop; + workingNode->growth = inGrowth; + workingNode->majority = inMajority; + // set nextPtr to null + workingNode->nextPtr = NULL; + // return node + return workingNode; +} + +/* +Name: privateCreateNodeFromNode +Process: creates linked list node provided another node +Function input/parameters: other node (const StateDataType) +Function output/parameters: none +Function output/returned: pointer to created node (StateDataType *) +Device input/---: none +Device output/---: none +Dependencies: one line of code - privateCreateNodeFromData +*/ +StateDataType *privateCreateNodeFromNode( const StateDataType source ) +{ + // return the node + return privateCreateNodeFromData(source.name, source.population, + source.growth, source.majority); +} + +/* +Name: privateCopyString +Process: copies string character for character up to NULL_CHAR of source string +Function input/parameters: source string to be copied (const char *) +Function output/parameters: destination string (char *) +Function output/returned: none +Device input/---: none +Device output/---: none +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, characterCount is in the right place for \0 + dest[characterCount] = NULL_CHAR; + // no return, void +} + +/* +Name: removeItemAtIndex +Process: removes node from linked list at index, + returns true if found, false otherwise +Function input/parameters: pointer to state linked list type (StateLLType *), + index to remove (int) +Function output/parameters: pointer to updated state linked list type + (StateLLType *), + pointer to removed item (StateDataType *) +Function output/returned: Boolean result of removal operation (bool) +Device input/---: none +Device output/---: none +Dependencies: deepCopyData, free, setItemToEmpty +*/ +bool removeItemAtIndex( StateLLType *stateData, + StateDataType *removedItem, int removeIndex ) +{ + // return false (temp) + return false; +} + +/* +Name: setItemToEmpty +Process: sets state data type struct to empty or default values, + including empty string and majority 'x' +Function input/parameters: pointer to state data value (StateDataType *) +Function output/parameters: pointer to updated state data value + (StateDataType *) +Function output/returned: none +Device input/---: none +Device output/---: none +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 +} \ No newline at end of file diff --git a/PA06-1018/Makefile b/PA06-1018/Makefile index 62901a1..d2f3414 100644 --- a/PA06-1018/Makefile +++ b/PA06-1018/Makefile @@ -1,19 +1,19 @@ CC = gcc -Wall -SOURCES = PA05_Main.c ArrayDataEngine.c IteratorUtility.c QueueUtility.c StackUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c -OBJECTS = PA05_Main.o ArrayDataEngine.o IteratorUtility.o QueueUtility.o StackUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o +SOURCES = PA06_Main.c LLDataEngine.c IteratorUtility.c QueueUtility.c StackUtility.c Console_IO_Utility.c File_Input_Utility.c File_Output_Utility.c +OBJECTS = PA06_Main.o LLDataEngine.o IteratorUtility.o QueueUtility.o StackUtility.o Console_IO_Utility.o File_Input_Utility.o File_Output_Utility.o # Uses the template structure defined in the TypicalUtils folder -all: PA05_Main +all: PA06_Main -PA05_Main: $(OBJECTS) - $(CC) $(OBJECTS) -o PA05_Main +PA06_Main: $(OBJECTS) + $(CC) $(OBJECTS) -o PA06_Main -PA05_Main.o: PA05_Main.c - $(CC) -c PA05_Main.c -o PA05_Main.o +PA06_Main.o: PA06_Main.c + $(CC) -c PA06_Main.c -o PA06_Main.o -ArrayDataEngine.o: ArrayDataEngine.c - $(CC) -c ArrayDataEngine.c -o ArrayDataEngine.o +LLDataEngine.o: LLDataEngine.c + $(CC) -c LLDataEngine.c -o LLDataEngine.o QueueUtility.o: QueueUtility.c $(CC) -c QueueUtility.c -o QueueUtility.o @@ -34,13 +34,13 @@ File_Output_Utility.o: File_Output_Utility.c $(CC) -c File_Output_Utility.c -o File_Output_Utility.o clean: - rm -f $(OBJECTS) PA05_Main PA05_Main.out + rm -f $(OBJECTS) PA06_Main PA06_Main.out clean_objects: rm -f $(OBJECTS) run: - ./PA05_Main + ./PA06_Main run_win: - PA05_Main + PA06_Main diff --git a/PA06-1018/PA06_Main b/PA06-1018/PA06_Main new file mode 100755 index 0000000000000000000000000000000000000000..2b67098efadf81c71fb868e4c014e6a1e746fba8 GIT binary patch literal 33632 zcmeHwdwf*Ywf{+Yh!9Os(1;I45k!HQAV|R11Q?iT0x={u6>%7n$wQM&n1_HGKqFqJ zL+*{eYSC7uYFqC|+YeUCrMAW3gP^q*K4o6_S$Pd&di(*uA)WhX=#SKh8dR|RN8iu#5kF-?H0ZPa2ol>3HX1a zah5R><>3M+=}rkil~-4~6^>&3FhG*arkf=242d=rR2C8>xl~u}Xh~7f$dYA}8$q{R zw!^p1lY9y)x>=u7(#?i(`BB!Vpe{$gnYu#CO>MBk82d%FU&#@gl(vrXROV?c*e!Ea)SPxnZg9J%Yi?N zsl`jm4Vc|dICi6vzEPHyKBA3dI`O}Kc*lRe{Pg~jR~+}wlAXW2zxBKGK3PvZWH-qW z4_%~>T_VbKpN&7_k^Z<%;0Z_9Yra=FVr1F=e+>{kv@N8&Qs8H#z<&t51Aq4GOdyi! zFHV84NP!Qgz;8=|r}UJp-l7zE@?SFkD^lQHDe#^Y_;gg@0L^}#0z|TU>r>!MQ{Zn; zfxkHg{=O9Wu_^344*cif@2IP~#u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t5Kk5-%4IR?^aNqZz%f}pMvWlPtVd-Sv^lzu!JkK+plbB#SQsX$*br43br$&s^8xJ zAF%v<=2M>+P*8oofaJ+%cKIIzM?O*d&HXg*t0}(q%ijM#0#TQDu$+QUo5PuGR`WBP z{K~PiHU$;GvO$#<+-{R^VtEDi?{tz5C8yx8ZSv}zP{HYZUPH2UDLGlf_ttQuw_iP{ zQBZwOMe*DH_X5kS{x_V=$QBwqC&a~XfY4b`vM)N@h=={w{4Wv~Ao5Ow)nm*iG3 zM1xbi?DZc4?L_?Xur;6CtM|d%`BhoL&mfzr$*a%jtK(f2w|! qe{uY0+KyZEit&NygE%kKFIBI?(Qs95S2%)q-YiQKYy!5T@qYm2zJ{Uz literal 0 HcmV?d00001 diff --git a/PA06-1018/PA06_Main.c b/PA06-1018/PA06_Main.c index 1501d59..d585c27 100644 --- a/PA06-1018/PA06_Main.c +++ b/PA06-1018/PA06_Main.c @@ -4,7 +4,7 @@ #include "StackUtility.h" #include "QueueUtility.h" -// local constants for program +// local constants for program, unneeded? const int INITIAL_NUM_STATES = 10; // function prototypes @@ -18,8 +18,8 @@ int main() // initialize variables StateLLType *wkgLL; StateDataType tempData; - IteratorType *iterator; - StackType *stack; + //IteratorType *iterator; + //StackType *stack; QueueType *queue; int index, testLimit, testStart = 0; @@ -28,120 +28,122 @@ int main() showTitle(); // set up data - wkgLL = createDataStructure( INITIAL_NUM_STATES ); - iterator = createIterator( INITIAL_NUM_STATES ); - stack = createStack( INITIAL_NUM_STATES ); - queue = createQueue( INITIAL_NUM_STATES ); + wkgLL = createDataStructure(); + //iterator = createIterator(); + //stack = createStack(); + queue = createQueue(); // Upload data if( uploadStateData( wkgLL, "StateData.csv" ) ) { // Testing for iterators - printf( "\nIterator Test Bed ---------------------------------\n\n" ); + // printf( "\nIterator Test Bed ---------------------------------\n\n" ); - copyDataList( iterator->iterData, wkgLL ); + // copyDataList( iterator->iterData, wkgLL ); - printf( "Iterate across list, first to last\n" ); + // printf( "Iterate across list, first to last\n" ); - getFirst( iterator, &tempData ); + // getFirst( iterator, &tempData ); - printf( "First name: %s\n", tempData.name ); + // printf( "First name: %s\n", tempData.name ); - while( getNext( iterator, &tempData ) ) - { - printf( "Next name: %s\n", tempData.name ); - } + // while( getNext( iterator, &tempData ) ) + // { + // printf( "Next name: %s\n", tempData.name ); + // } - printf( "\nIterate across list, last to first\n" ); + // printf( "\nIterate across list, last to first\n" ); - getLast( iterator, &tempData ); + // getLast( iterator, &tempData ); - printf( "Last name: %s\n", tempData.name ); + // printf( "Last name: %s\n", tempData.name ); - while( getPrevious( iterator, &tempData ) ) - { - printf( "Prior name: %s\n", tempData.name ); - } + // while( getPrevious( iterator, &tempData ) ) + // { + // printf( "Prior name: %s\n", tempData.name ); + // } - // Testing for Stacks - printf( "\nStack Test Bed ------------------------------------\n\n" ); + // // Testing for Stacks + // printf( "\nStack Test Bed ------------------------------------\n\n" ); - printf( "Push items on stack:\n" ); + // printf( "Push items on stack:\n" ); - testLimit = 10; - for( index = testStart; index < testLimit; index++ ) - { - getItemAtIndex( &tempData, *wkgLL, index ); + // testLimit = 10; + // for( index = testStart; index < testLimit; index++ ) + // { + // getItemAtIndex( &tempData, *wkgLL, index ); - printf( "Pushing: %s\n", tempData.name ); + // printf( "Pushing: %s\n", tempData.name ); - pushStack( stack, tempData ); - } + // pushStack( stack, tempData ); + // } - printf( "\nCurrent stack: " ); + // printf( "\nCurrent stack: " ); - testStart = 0; - for( index = testStart; index < getListSize( *stack ); index++ ) - { - getItemAtIndex( &tempData, *stack, index ); + // testStart = 0; + // for( index = testStart; index < getListSize( *stack ); index++ ) + // { + // getItemAtIndex( &tempData, *stack, index ); - printf( "%s | ", tempData.name ); - } + // printf( "%s | ", tempData.name ); + // } - printf( "<- Top of stack\n\nPop items from stack:\n" ); + // printf( "<- Top of stack\n\nPop items from stack:\n" ); - testLimit = 5; - for( index = testStart; index < testLimit; index++ ) - { - popStack( &tempData, stack ); + // testLimit = 5; + // for( index = testStart; index < testLimit; index++ ) + // { + // popStack( &tempData, stack ); - printf( "Popping: %s\n", tempData.name ); - } + // printf( "Popping: %s\n", tempData.name ); + // } - printf( "\nCurrent stack: " ); + // printf( "\nCurrent stack: " ); - for( index = testStart; index < getListSize( *stack ); index++ ) - { - getItemAtIndex( &tempData, *stack, index ); + // for( index = testStart; index < getListSize( *stack ); index++ ) + // { + // getItemAtIndex( &tempData, *stack, index ); - printf( "%s | ", tempData.name ); - } + // printf( "%s | ", tempData.name ); + // } - printf( "<- Top of stack\n\nPush more items on stack:\n" ); + // printf( "<- Top of stack\n\nPush more items on stack:\n" ); - testStart = 10; testLimit = 15; - for( index = testStart; index < testLimit; index++ ) - { - getItemAtIndex( &tempData, *wkgLL, index ); + // testStart = 10; testLimit = 15; + // for( index = testStart; index < testLimit; index++ ) + // { + // getItemAtIndex( &tempData, *wkgLL, index ); - printf( "Pushing: %s\n", tempData.name ); + // printf( "Pushing: %s\n", tempData.name ); - pushStack( stack, tempData ); - } + // pushStack( stack, tempData ); + // } - printf( "\nCurrent stack: " ); + // printf( "\nCurrent stack: " ); - testStart = 0; - for( index = testStart; index < getListSize( *stack ); index++ ) - { - getItemAtIndex( &tempData, *stack, index ); + // testStart = 0; + // for( index = testStart; index < getListSize( *stack ); index++ ) + // { + // getItemAtIndex( &tempData, *stack, index ); - printf( "%s | ", tempData.name ); - } + // printf( "%s | ", tempData.name ); + // } - printf( "<- Top of stack\n\nPopping until empty:\n" ); + // printf( "<- Top of stack\n\nPopping until empty:\n" ); - while( popStack( &tempData, stack ) ) - { - printf( "Popping: %s\n", tempData.name ); - } + // while( popStack( &tempData, stack ) ) + // { + // printf( "Popping: %s\n", tempData.name ); + // } // Testing for Queues printf( "\nQueue Test Bed ------------------------------------\n\n" ); printf( "Enqueue items:\n" ); + //printf("\nList Size: %d\n", getListSize(*queue)); + testStart = 0; testLimit = 10; for( index = testStart; index < testLimit; index++ ) { @@ -152,6 +154,8 @@ int main() enqueue( queue, tempData ); } + //printf("\nList Size: %d\n", getListSize(*queue)); + printf( "\nCurrent queue: Rear -> " ); testStart = 0; @@ -234,9 +238,9 @@ int main() wkgLL = clearDataStructure( wkgLL ); - iterator = clearIterator( iterator ); + //iterator = clearIterator( iterator ); - stack = clearStack( stack ); + //stack = clearStack( stack ); queue = clearQueue( queue ); diff --git a/PA06-1018/QueueUtility.c b/PA06-1018/QueueUtility.c new file mode 100644 index 0000000..39c842b --- /dev/null +++ b/PA06-1018/QueueUtility.c @@ -0,0 +1,106 @@ +// header files +#include "QueueUtility.h" + +/* Data Structures +typedef struct StateArrayStruct + { + StateDataType *array; + + int size, capacity; + } QueueType; (aka StateArrayType) +Data Structures*/ + +// function implementations + +/* +Name: clearQueue +Process: clears QueueType, returns NULL +Function input/parameters: pointer to queue type (QueueType *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: clearDataStructure +*/ +QueueType *clearQueue( QueueType *queue ) +{ + // clear the entire data structure + clearDataStructure(queue); + // return NULL + return NULL; +} + +/* +Name: createQueue +Process: creates QueueType, initializes front index to zero, + rear index to -1, returns pointer to data structure +Function input/parameters: initial capacity (int) +Function output/parameters: none +Function output/returned: pointer to queue type (QueueType *) +Device input/---: none +Device output/---: none +Dependencies: createDataStructure +*/ +QueueType *createQueue() +{ + // create the data structure + QueueType *queueDataStructure; + queueDataStructure = createDataStructure(); + // return QueueType + return queueDataStructure; +} + +/* +Name: peekFront +Process: captures value at front of queue + returns true if successful and sets return value, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to queue type (QueueType *) +Function output/parameters: pointer to return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex, getListSize +*/ +bool peekFront( StateDataType *returnVal, const QueueType queue ) +{ + // use getListSize to get the 'front' value + // use getItemAtIndex to 'see' the value at the front. + return getItemAtIndex(returnVal, queue, getListSize(queue) - 1); +} + +/* +Name: dequeue +Process: captures value at front of queue, removes and returns value, + returns true if successful, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to queue type (QueueType *) +Function output/parameters: pointer to return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: removeItemAtIndex, getListSize +*/ +bool dequeue( StateDataType *returnVal, QueueType *queue ) +{ + // get the "front" of the queue + // remove the value in the queue and return success/failure + return removeItemAtIndex(queue, returnVal, getListSize(*queue) - 1); +} + +/* +Name: enqueue +Process: sets value at rear of queue + returns true if successful, false otherwise +Function input/parameters: pointer to queue type (QueueType *) +Function output/parameters: value to be pushed (const StateDataType) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: insertItemAtIndex +*/ +bool enqueue( QueueType *queue, const StateDataType toBePushed ) +{ + // return function success/failure based on inputs + return insertItemAtIndex(queue, toBePushed, 0); +} \ No newline at end of file diff --git a/PA06-1018/QueueUtility.h b/PA06-1018/QueueUtility.h index 4d0c775..717847e 100644 --- a/PA06-1018/QueueUtility.h +++ b/PA06-1018/QueueUtility.h @@ -32,7 +32,7 @@ Device input/---: none Device output/---: none Dependencies: createDataStructure */ -QueueType *createQueue( int initialCapacity ); +QueueType *createQueue(); /* Name: peekFront diff --git a/PA06-1018/StackUtility.c b/PA06-1018/StackUtility.c new file mode 100644 index 0000000..ae97a1a --- /dev/null +++ b/PA06-1018/StackUtility.c @@ -0,0 +1,103 @@ +// header files +#include "StackUtility.h" + +/* Data Structures +typedef struct StateArrayStruct + { + StateDataType *array; + + int size, capacity; + } StackType; (aka StateArrayType) +Data Structures*/ + +// function implementations + +/* +Name: clearStack +Process: clears StackType, returns NULL +Function input/parameters: pointer to stack type (StackType *) +Function output/parameters: none +Function output/returned: NULL +Device input/---: none +Device output/---: none +Dependencies: clearDataStructure +*/ +StackType *clearStack( StackType *stackData ) +{ + // clear the entire data structure + clearDataStructure(stackData); + // return NULL + return NULL; +} + +/* +Name: createStack +Process: creates StackType, returns pointer to it +Function input/parameters: initial capacity (int) +Function output/parameters: none +Function output/returned: pointer to stack type (StackType *) +Device input/---: none +Device output/---: none +Dependencies: createDataStructure +*/ +StackType *createStack( int initialCapacity ) +{ + // create the data structure + StackType *stackDataStructure; + stackDataStructure = createDataStructure(initialCapacity); + // return StackType + return stackDataStructure; +} + +/* +Name: peekTop +Process: captures value at top of stack, returns, + returns true if successful, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to stack type (StackType *) +Function output/parameters: pointer to return value (StateDataType *) +Function output/returned: Boolean result of operation (bool) +Device input/---: none +Device output/---: none +Dependencies: getItemAtIndex, getListSize +*/ +bool peekTop( StateDataType *returnVal, const StackType stackData ) +{ + // return the getItemAtIndex success/failure + return getItemAtIndex(returnVal, stackData, getListSize(stackData)); +} + +/* +Name: popStack +Process: captures value at top of stack, removes and returns, + returns true if successful, + otherwise, sets return value to empty, returns false +Function input/parameters: pointer to stack type (StackType *) +Function output/parameters: pointer to return value (StateDataType *) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: removeItemAtIndex, getListSize +*/ +bool popStack( StateDataType *returnVal, StackType *stackData ) +{ + // return function success/failure based on inputs + return removeItemAtIndex(stackData, returnVal, getListSize(*stackData)); +} + +/* +Name: pushStack +Process: sets value at top of stack, + returns true if successful, false otherwise +Function input/parameters: pointer to stack type (StackType *) +Function output/parameters: value to be pushed (const StateDataType) +Function output/returned: Boolean result of operation +Device input/---: none +Device output/---: none +Dependencies: insertItemAtIndex, getListSize +*/ +bool pushStack( StackType *stackData, const StateDataType toBePushed ) +{ + // return function success/failure based on operation + return insertItemAtIndex(stackData, toBePushed, getListSize(*stackData)); +} \ No newline at end of file