aboutsummaryrefslogtreecommitdiffstats
path: root/P1
diff options
context:
space:
mode:
Diffstat (limited to 'P1')
-rw-r--r--P1/src/mapper.c26
-rw-r--r--P1/src/reducer.c10
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);
}
}