Question: #include #include //HINT: you'll be using this! #include #define MAXCITYNAME 30 #define MAXLINELENGTH 50 typedef struct n_ { int zipCode; //A zip code that exists
#include
#include
//HINT: you'll be using this!
#include
#define MAXCITYNAME 30
#define MAXLINELENGTH 50
typedef struct n_
{
int zipCode; //A zip code that exists in the given city/state
char* city; //Will point to a city name
char state[3]; //A state abbreviation. Note that we need
//room for the NULL
terminator!
struct n_* left; //connections to other nodes
struct n_* right;
} Node;
Node* importTree(char* filename);
Node* addNode(Node* root, Node* newNode);
int findStateCount(Node* root, char* state);
Node* findZipCode(Node* root, int zipCode);
void freeTree(Node* root);
int main(int argc, char** argv)
{
}
Node* addNode(Node* root, Node* newNode)
{
}
int findStateCount(Node* root, char* state)
{
}
Node* findZipCode(Node* root, int zip)
{
}
void freeTree(Node* root)
{
}
Node* importTree(char* filename)
{
Node* root = NULL;
FILE* fp = fopen(filename, "r");
if(!fp)
{
printf("Error opening file. ");
return NULL;
}
while(!feof(fp))
{
Node* new = malloc(sizeof(Node));
if(!new)
{
printf("Failed to allocate memory. Ending
read. ");
exit(1);
}
new->city = malloc(sizeof(char)*MAXCITYNAME);
if(!(new->city))
{
printf("Failed to allocate memory. Ending
read. ");
exit(1);
}
new->left = NULL;
new->right = NULL;
char* line = malloc(sizeof(char)*MAXLINELENGTH);
if(!line)
{
printf("Failed to allocate memory. Ending
read. ");
exit(1);
}
if(fgets(line, MAXLINELENGTH, fp) == NULL)
{
if(!feof(fp))
{
printf("File reading ended prematurely.
Check for errors in the file. ");
exit(1);
}
free(new->city);
free(line);
free(new);
fclose(fp);
break;
}
char* tmp = strtok(line, ",");
new->zipCode = atoi(tmp);
tmp = strtok(NULL, ",");
strcpy(new->city, tmp);
new->city[strlen(tmp)+1] = '\0';
tmp = strtok(NULL, ",");
strcpy(new->state, tmp);
new->state[2] = '\0';
root = addNode(root, new);
if(!root)
{
printf("Root of tree is still NULL! Ending
read. ");
exit(1);
}
free(line);
}
return root;
}



![name char state[3]; //A state abbreviation. Note that we need //room for](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3175516a05_25266f31754afacd.jpg)
STARTER CODE


Directions: Complete the following homework assignment using the description given in each section. Purpose: Use of binary trees . Use of argc/argj Submission Info: If your file is called homework3.c then the submission command would be submit CS2050 2050HW3 homework3.c Description: Part of the advantages of binary trees, or any tree in particular, is that you are able to make sense of large data sets. In this homework, you will have two input files, each containing 5000 entries. However, it is relatively easy to get what we want out of the data through binary trees. Note that the data in the dataset is real data; this makes it easier to check your work. Also note that there is no file format given, because the function to parse through the data is given to you Structure Definition typedef struct n int zipCode: 1/A zip code that exists in the given city/state char* city; //Will point to a city name char state [3] //A state abbreviation. Note that we need //room for the NULL terminator! struct n* left; //connections to other nodes struct n* right; ) Node Function Prototvpes Node* addNode(Node* root, Node newNode) Input: the root of the tree, and the new node ready to be added to the tree Return: the root of the tree
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
