Answered step by step
Verified Expert Solution
Question
1 Approved Answer
// insert stores a string (s) in the sorted binary tree, // specified by its root (tree). // It returns 0 if string (s) has
// insert stores a string (s) in the sorted binary tree, | ||||||
// specified by its root (tree). | ||||||
// It returns 0 if string (s) has been successfully inserted | ||||||
// (i.e. no duplicates) | ||||||
// It returns 1 if the string has not been inserted (due to duplicates) | ||||||
// Hint: you can use strcmp(..) to compare two NULL-terminated C strings | ||||||
// type "man strcmp" to learn how to use it. | ||||||
int | ||||||
insert(tnode_t *tree, char *s) | ||||||
{ | ||||||
// TODO: Your code here | ||||||
} | ||||||
// pre-order performs a preorder traversal of the sorted binary tree | ||||||
// and store the sequence of strings visited along the way in | ||||||
// the array argument (result) whose allocated size is result_max | ||||||
// It returns the number of strings stored in the result array. | ||||||
// (Our tester part7_harness.c will allocate an array whose size (result_max) is | ||||||
// larger than the number of strings to be stored.) | ||||||
// In preorder traversal, you print the value in node n first, and then | ||||||
// visit n's left child, and then visit n's right child. | ||||||
// For example, for the tree below, the preorder traversal result is "a" "d" "b" "e" | ||||||
// "a" | ||||||
// \ | ||||||
// "d" | ||||||
// / \ | ||||||
// "b" "e" | ||||||
// | ||||||
// Note: you are free to write an auxilary function and use it here. | ||||||
int | ||||||
preorder(tnode_t *tree, char **result, int result_max) | ||||||
{ | ||||||
// TODO: your code here | ||||||
} | ||||||
// inorder performs an inorder traversal of the sorted binary tree | ||||||
// and store the sequence of strings visited along the way in | ||||||
// the array argument (result) whose allocated size is result_max | ||||||
// It returns the number of strings stored in the result array. | ||||||
// (Our tester part7_harness.c will allocate an array whose size (result_max) is | ||||||
// larger than the number of strings to be stored.) | ||||||
// In inorder traversal, you visit node n's left child first, then print the value in node n, and then | ||||||
// visit node n's right child. | ||||||
// For example, for the tree below, the inorder traversal result is "a" "b" "d" "e" | ||||||
// "a" | ||||||
// \ | ||||||
// "d" | ||||||
// / \ | ||||||
// "b" "e" | ||||||
// | ||||||
// Note: you are free to write an auxilary function and use it here. | ||||||
int | ||||||
inorder(tnode_t *tree, char **result, int max_result) | ||||||
{ | ||||||
// TODO: your code here | ||||||
} | ||||||
// del_tree de-allocates all nodes in the tree | ||||||
// you should do not de-allocate the strings stored inside each node | ||||||
void | ||||||
del_tree(tnode_t *tree) | ||||||
{ | ||||||
// TODO: your code here | ||||||
} --------
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started