From bc496e01e4d1912dceed941bf8502bef1eeb14a5 Mon Sep 17 00:00:00 2001 From: cdez Date: Wed, 18 Oct 2023 15:39:05 -0700 Subject: [PATCH] "Finished" PA06 +- LLDataEngine.c +- PA06_Main +- QueueUtility.c --- PA06-1018/LLDataEngine.c | 128 ++++++++++++++++++++++++++++++++++++++- PA06-1018/PA06_Main | Bin 33632 -> 33632 bytes PA06-1018/QueueUtility.c | 4 +- 3 files changed, 127 insertions(+), 5 deletions(-) diff --git a/PA06-1018/LLDataEngine.c b/PA06-1018/LLDataEngine.c index 21c4f1b..e32ed5a 100644 --- a/PA06-1018/LLDataEngine.c +++ b/PA06-1018/LLDataEngine.c @@ -172,7 +172,23 @@ Dependencies: deepCopyData, setItemToEmpty bool getItemAtIndex( StateDataType *returnVal, const StateLLType stateData, int listIndex ) { - // return false (temp) + int llIncrementer = 0; + StateDataType *currentPtr = stateData.headPtr; + // while through linked list + while(!listIsEmpty(stateData) && currentPtr != NULL) + { + // look for listIndex + if(listIndex == llIncrementer) + { + // if found, return true, copy data into return + deepCopyData(returnVal, currentPtr); + return true; + } + llIncrementer = llIncrementer + 1; + } + // since not found, return empty value in returnVal. + setItemToEmpty(returnVal); + // return false since not found, or not within bounds. return false; } @@ -221,7 +237,60 @@ Dependencies: privateCreateNodeFromNode bool insertItemAtIndex( StateLLType *stateData, StateDataType toBeInserted, int insertIndex ) { - // return false (temp) + int llIncrementer = 0; + StateDataType *currentPtr = stateData->headPtr; + StateDataType *insertedNode; + // while through linked list + while(!listIsEmpty(*stateData) && currentPtr != NULL) + { + // checks within middle of list + if(insertIndex == llIncrementer) + { + // if found, return true, insert data + // create node given toBeInserted + insertedNode = privateCreateNodeFromNode(toBeInserted); + // move the node's nextPtr to currentPtr->nextPtr + currentPtr->nextPtr = insertedNode->nextPtr; + // move the currentPtr's nextPtr to the node + currentPtr = insertedNode; + return true; + } + llIncrementer = llIncrementer + 1; + } + // need a check for beginning of list + if(insertIndex == 0) + { + if(stateData->headPtr == NULL) + { + // if at beginning of list, but no more data + // create node given toBeInserted + insertedNode = privateCreateNodeFromNode(toBeInserted); + // move the headPtr to node + stateData->headPtr = insertedNode; + return true; + } + // if at beginning of list, if more data in list + // create node given toBeInserted + insertedNode = privateCreateNodeFromNode(toBeInserted); + // need to point the headPtr->nextPtr to the node's nextPtr + stateData->headPtr->nextPtr = insertedNode->nextPtr; + // move the headPtr to node + stateData->headPtr = insertedNode; + return true; + } + // put the end of list check out here? + if(insertIndex == getListSize(*stateData)) + { + // if found, return true, append data + // create node given toBeInserted + insertedNode = privateCreateNodeFromNode(toBeInserted); + // move the node's nextPtr to NULL + insertedNode->nextPtr = NULL; + // move the currentPtr's nextPtr to the node + currentPtr = insertedNode; + return true; + } + // return false since not inserted, or not within bounds. return false; } @@ -356,7 +425,60 @@ Dependencies: deepCopyData, free, setItemToEmpty bool removeItemAtIndex( StateLLType *stateData, StateDataType *removedItem, int removeIndex ) { - // return false (temp) + int llIncrementer = 0; + StateDataType *currentPtr = stateData->headPtr; + // while through linked list + while(!listIsEmpty(*stateData) && currentPtr != NULL) + { + // checks within middle of list + if(removeIndex == llIncrementer) + { + // if found, return true, insert data + // copy data out of the list + deepCopyData(removedItem, currentPtr); + // move the pointer of currentPtr to the next item + currentPtr->nextPtr = currentPtr->nextPtr->nextPtr; + // free the memory of the removed item. + free(currentPtr->nextPtr); + return true; + } + llIncrementer = llIncrementer + 1; + } + // need a check for beginning of list + if(removeIndex == 0) + { + if(stateData->headPtr == NULL) + { + // if at beginning of list, but no more data + // copy data out of the list + deepCopyData(removedItem, currentPtr); + // free the memory of the removed item. + free(currentPtr->nextPtr); + return true; + } + // if at beginning of list, if more data in list + // copy data out of the list + deepCopyData(removedItem, currentPtr); + // move the pointer of currentPtr to the next item + currentPtr->nextPtr = currentPtr->nextPtr->nextPtr; + // free the memory of the removed item. + free(currentPtr->nextPtr); + return true; + } + // put the end of list check out here? + if(removeIndex == getListSize(*stateData)) + { + // if found, return true, append data + // copy data out of the list + deepCopyData(removedItem, currentPtr); + // move the pointer of currentPtr to the next item + currentPtr->nextPtr = currentPtr->nextPtr->nextPtr; + // free the memory of the removed item. + free(currentPtr->nextPtr); + return true; + } + setItemToEmpty(removedItem); + // return false since not inserted, or not within bounds. return false; } diff --git a/PA06-1018/PA06_Main b/PA06-1018/PA06_Main index 2b67098efadf81c71fb868e4c014e6a1e746fba8..211bcd8159d7daef6afa2e3be6b7d3b8667c70c7 100755 GIT binary patch delta 5463 zcma)<3sjWV7RSFi0xF__@^ZvsK;$vt2nd3pMtX-v#J4F~n)wPbAC;J1rMZEc!|3g? zZ$`Dsymnn)vQlaJNKHhq6m?7UHN51Z!tf|bDaS|6{h#kUz-afbb!RQs?|ggjv(Mi9 zoPEBJy3MR^Guzio43k z8{|p`|CubXFTLkKmM!q0D*vt7FZoH*#uCqs168ozW_aCbF06(y%02? z!{{&%)b?6{B$*9ol?N*vD5GuulC;F=`ErTTY_KY#qg~4VesnHi?dZupl%VnrTUE+( zVu?$GI^8Vvk)-@~6@uENb~qf0qYemZ%7{SPIWU;*a-q`$|G{cqXqh^a9qCcLT|Gx- z%5RG?nsaSNb55Q4@#-=|2anZgG1MU(duy1*P@Q7v$Wa?DkJ}-I-6fvukH29F=g5&Y$05Fa zLmLkc&XR1Q{Fzrs4z69wc{M-xg5h4Z1+0Qq5x(u#Wk-k zHydwT^anE(kC$qCrikc)nXL;tqgnd9!!gQmAt!_T3AX*lgXmt)ZY)d96qS%uqL-um z>50G$cIGCjf_>;{U;xXyMHd4b{^t(blnUBgCy7mbRBR%)R^G&ryAFp^!qiMrMyw^u zXn_nHJ^N>|(arY|j@WB>PO@o`057LWsV6r3o&4NtDd#1)l$S;=hds37{yR=9!u#F! zPVXP^{FO7-8Qw-`V`Z2B5Z;k?he;g7`O3OUw!(Y7veh|bAM%&*fB4Jp45-x`?hr|t zttTRryXk?Giyb!D&+wS3X7K2KadwdyCfv9o?@)@yJ#q)!bsp5R)Lwi;ErvF8nbMuZ zr(-mK#}kgZP4j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|| z$Re-{ECUDNCfxzP4c38MaS_|VS-8m^VDb(0N8KF;b3he78b#n7u)GY7U1;n8FM@TT zUmp^HTR{hy^lv0U^{)eSz*ArmsK1Q~fG5EnVDKIE2Ma+PxF2+Y5qHslupq1jb3pOI zwIn{Z*`{h)6uuCGU>Y2_nT_}NdCG4fc3r?1N;rU@FtKzwFM3?=d6z5H)0N-v>V+!} zaoooJS*G>J{qT!Nd!8DmC=>N)7Qnj3)5@%FuQ=co#P^-2?n%n>*Jq)fvQpLfq&XU-~Gn5qe<=Y;?IMcpBC{G6;SH1R9`$Q{!hFV@!L&QgKSYYY5-zv*jW|R+DKthvC%ft0W)ow zkcw@wkrnvVMwP%}8`S^}=m$(}rf#6HnG};%Y(+EafZArV0EQN_0&y)=2^d?b23X!g z4ZtTY)D1XVNHImlCbg0d*xX7MApZh(PQ{kt{sq3cKsCUSHdKjHd0AArFi$xlPBKUFK08pDVjqK^4#5=|LmdmVWJ-!yq$%H@AemCR z*B_N9dbjZ$JGmao^>@-GVGP%ExL)#@UdZ)0on%bm{$10&MnF_ z{>10&K46F*p1qo-e$x>oa+PMEU9=^}JJ&31mB?fj!OZ6prrGtWmq>>e8q@8k zr3R%gR!ZW&ZqQuEU1=&(SPkX#9}Dl{;ar~F{c%9ITCVTq8<;3%6~5&9yf{hV^(8cO z{XJeS?&}EQZewe)v3*L%4BNi=O-VPJ<;bZCXalEHUy z6?aX2~=NhP@Li0ha2{OdC7qP0MD-cD*ylh diff --git a/PA06-1018/QueueUtility.c b/PA06-1018/QueueUtility.c index 39c842b..5023663 100644 --- a/PA06-1018/QueueUtility.c +++ b/PA06-1018/QueueUtility.c @@ -66,7 +66,7 @@ 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); + return getItemAtIndex(returnVal, queue, getListSize(queue)); } /* @@ -85,7 +85,7 @@ 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); + return removeItemAtIndex(queue, returnVal, getListSize(*queue)); } /*