Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given a textfile of sorted strings from a-z, what code can search for a word in

ID: 3547302 • Letter: G

Question

Given a textfile of sorted strings from a-z, what code can search for a word in the array created by output of the textfile.

the textfile is a 1 column(1000) words

i need insert-> to BST

i need search-> from BST

output boolean

Explanation / Answer

#include #include struct bin_tree { int data; struct bin_tree * right, * left; }; typedef struct bin_tree node; void insert(node ** tree, int val) { node *temp = NULL; if(!(*tree)) { temp = (node *)malloc(sizeof(node)); temp->left = temp->right = NULL; temp->data = val; *tree = temp; return; } if(val < (*tree)->data) { insert(&(*tree)->left, val); } else if(val > (*tree)->data) { insert(&(*tree)->right, val); } } void print_preorder(node * tree) { if (tree) { printf("%d ",tree->data); print_preorder(tree->left); print_preorder(tree->right); } } void print_inorder(node * tree) { if (tree) { print_inorder(tree->left); printf("%d ",tree->data); print_inorder(tree->right); } } void print_postorder(node * tree) { if (tree) { print_postorder(tree->left); print_postorder(tree->right); printf("%d ",tree->data); } } void deltree(node * tree) { if (tree) { deltree(tree->left); deltree(tree->right); free(tree); } } node* search(node ** tree, int val) { if(!(*tree)) { return NULL; } if(val < (*tree)->data) { search(&((*tree)->left), val); } else if(val > (*tree)->data) { search(&((*tree)->right), val); } else if(val == (*tree)->data) { return *tree; } } void main() { node *root; node *tmp; //int i; root = NULL; /* Inserting nodes into tree */ insert(&root, 9); insert(&root, 4); insert(&root, 15); insert(&root, 6); insert(&root, 12); insert(&root, 17); insert(&root, 2); /* Printing nodes of tree */ printf("Pre Order Display "); print_preorder(root); printf("In Order Display "); print_inorder(root); printf("Post Order Display "); print_postorder(root); /* Search node into tree */ tmp = search(&root, 4); if (tmp) { printf("Searched node=%d ", tmp->data); } else { printf("Data Not found in tree. "); } /* Deleting all nodes of tree */ deltree(root); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote