Got close to finishing
++ IteratorUtility.c ++ LLDataEngine.c ++ QueueUtility.c ++ StackUtility.c +- PA06_Main.c +- Makefile for PA06
This commit is contained in:
parent
635ce9ffad
commit
b7cb3dc9e0
8 changed files with 899 additions and 88 deletions
103
PA06-1018/StackUtility.c
Normal file
103
PA06-1018/StackUtility.c
Normal file
|
|
@ -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));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue