Got close to finishing

++ IteratorUtility.c
++ LLDataEngine.c
++ QueueUtility.c
++ StackUtility.c
+- PA06_Main.c
+- Makefile for PA06
This commit is contained in:
Charles Descamps 2023-10-17 20:48:30 -07:00
parent 635ce9ffad
commit b7cb3dc9e0
8 changed files with 899 additions and 88 deletions

View file

@ -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 );