Question: Binary Search Tree in C! Please help me finish this code and copy sample output in C Please do the TODO's #include #include #include #define

Binary Search Tree in C!

Please help me finish this code and copy sample output in C Please do the TODO's

#include #include #include

#define BUFSIZE 100 #define TRUE 1

//struct tree_node can be reference simply as Node typedef struct tree_node Node;

//struct definition of Node struct tree_node { char * value;

//TODO: complete struct tree_node definition };

//TODO: what other variables might you need?

/*----------------------------------------------------------------------------- * Function name: print * Input: pointer to a struct of type Node * Output: none * Result: the string value of node is printed * Notes: DO NOT EDIT THIS FUNCTION *---------------------------------------------------------------------------*/ void printNode(Node * node) { printf("%s ", node->value); }

/*----------------------------------------------------------------------------- * Function name: compare * Input: two char pointers * Output: 0 if both strings are equal * 0 the first character that does not match has a * greater value in ptr1 than in ptr2 * Notes: USE THIS TO COMPARE STRINGS WHEN INSERTING/FINDING *---------------------------------------------------------------------------*/ int compare(char * a, char *b) {

//TODO: your code goes here }

/*----------------------------------------------------------------------------- * Function name: insert * Input: char pointer * Output: none * Result: a node having input as value is inserted into it's * appropriate location in the tree *---------------------------------------------------------------------------*/ void insert(char* input) {

//TODO: your code goes here }

/*----------------------------------------------------------------------------- * Function name: find * Input: char pointer * Output: none * Result: see write-up *---------------------------------------------------------------------------*/ void find(char* input) {

//TODO: your code goes here }

/*----------------------------------------------------------------------------- * Function name: traverse * Input: none * Output: none * Result: the nodes in the tree are printed in order of increasing * value *---------------------------------------------------------------------------*/ void traverse() {

//TODO: your code goes here }

//DO NOT EDIT void insertPrompt() { char * input = malloc(sizeof(char)*(BUFSIZE+1)); printf("Enter a string to insert (max length 100): "); scanf("%s", input); insert(input); }

//DO NOT EDIT void lookupPrompt() { char * input = malloc(sizeof(char)*(BUFSIZE+1)); printf("Enter a string to look up: "); scanf("%s", input); find(input); }

//MUST MATCH STARTER CODE ON TURNIN int main() {

char input[BUFSIZE];

printf("Binary Search Tree! ");

while (!feof(stdin)) {

printf("Select an Operation: (i)nsert, (l)ookup, (p)rint in order, (q)uit: "); scanf("%s", input);

if (feof(stdin)) { break; } if (input[0]=='i') { insertPrompt(); } else if (input[0]=='l') { lookupPrompt(); } else if (input[0]=='p') { traverse(); } else if (input[0] == 'q') { break; } else { printf("Invalid option selected, try again "); } }

return 0; }

Please take a screenshot of your output so I know it works!

Thank you! :)

Sample Output:

 Binary Search Tree in C! Please help me finish this code

[cs12f6@ieng6-201]:HW:255$./a.out Binary Search Tree! Select an Operation: (i)nsert, (l)ookup, (p)rint in order, (q)uit: i Enter a string to insert (max length 100): Andrei Select an Operation: (i)nsert, (l)ookup, (p)rint in order, (q)uit: i Enter a string to insert (max length 100): Richard Select an Operation: (i)nsert, (l)ookup, (p)rint in order, (q)uit: i Enter a string to insert (max length 100): Marina Select an Operation: (i)nsert, (l)ookup, (p)rint in order, (q)uit: I Enter a string to look up: Andrei Found: Andrei Sele Operation: (i)nsert, (l)ookup, (p)rint in order, (q)uit: I Enter a string to look up: andrei NOT found: andrei Sele Operation: (i)nsert, (l)ookup, (p)rint in order, (q)uit: I Enter a string to look up: Marina Found: Marina Selet Operation: (i)nsert, (l)ookup, (p)rint in order, (q)uit: p Andrei Marina Richard Selet Operation: (i)nsert, (l)ookup, (p)rint in order, (q)uit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!