diff options
author | Matt Strapp <strap012@umn.edu> | 2020-09-28 12:01:54 -0500 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2020-09-28 12:01:54 -0500 |
commit | 6ab6284be9d6ff3c92a9b665750e8fe30e9931c5 (patch) | |
tree | 6526d707af1dd966206d10085ebb3359d791e40d /P1/src | |
parent | Fix makefile (diff) | |
download | csci4061-6ab6284be9d6ff3c92a9b665750e8fe30e9931c5.tar csci4061-6ab6284be9d6ff3c92a9b665750e8fe30e9931c5.tar.gz csci4061-6ab6284be9d6ff3c92a9b665750e8fe30e9931c5.tar.bz2 csci4061-6ab6284be9d6ff3c92a9b665750e8fe30e9931c5.tar.lz csci4061-6ab6284be9d6ff3c92a9b665750e8fe30e9931c5.tar.xz csci4061-6ab6284be9d6ff3c92a9b665750e8fe30e9931c5.tar.zst csci4061-6ab6284be9d6ff3c92a9b665750e8fe30e9931c5.zip |
"FIX" mapper + reducer from FAQ
Diffstat (limited to '')
-rw-r--r-- | P1/src/mapper.c | 26 | ||||
-rw-r--r-- | P1/src/reducer.c | 10 |
2 files changed, 18 insertions, 18 deletions
diff --git a/P1/src/mapper.c b/P1/src/mapper.c index 66ac2ef..1c4468b 100644 --- a/P1/src/mapper.c +++ b/P1/src/mapper.c @@ -23,11 +23,11 @@ valueList *insertNewValueToList(valueList *root, char *count){ void freeValueList(valueList *root) { if(root == NULL) return; - valueList *tempNode = root -> next;; - while (tempNode != NULL){ - free(root); - root = tempNode; - tempNode = tempNode -> next; + valueList *tempNode = NULL; + while (root != NULL){ + tempNode = root; + root = root -> next; + free(tempNode); } } @@ -64,14 +64,14 @@ intermediateDS *insertPairToInterDS(intermediateDS *root, char *word, char *coun // free the DS after usage. Call this once you are done with the writing of DS into file void freeInterDS(intermediateDS *root) { - if(root == NULL) return; - - intermediateDS *tempNode = root -> next;; - while (tempNode != NULL){ - freeValueList(root -> value); - free(root); - root = tempNode; - tempNode = tempNode -> next; +if(root == NULL) return; + +intermediateDS *tempNode = NULL; +while (root != NULL) { + tempNode = root; + root = root -> next; + freeValueList(tempNode -> value); + free(tempNode); } } diff --git a/P1/src/reducer.c b/P1/src/reducer.c index bdf093b..7afb9ee 100644 --- a/P1/src/reducer.c +++ b/P1/src/reducer.c @@ -33,11 +33,11 @@ finalKeyValueDS *insertNewKeyValue(finalKeyValueDS *root, char *word, int count) void freeFinalDS(finalKeyValueDS *root) { if(root == NULL) return; - finalKeyValueDS *tempNode = root -> next;; - while (tempNode != NULL){ - free(root); - root = tempNode; - tempNode = tempNode -> next; + finalKeyValueDS *tempNode = NULL; + while (root != NULL) { + tempNode = root; + root = root -> next; + free(tempNode); } } |