algorithm for this fucntion ?
the function list_t *matches(btree_t tree, char *prefix) takes a BST and searches it for phrases that begin with the same prefix, then inserts the phrases that match into a linked list in lexicographical order.
I am having trouble with an algorithm to this function.
In pseudo code I have thus far:
a recursive approach
compare = strncmp (phrase, prefix, strlen(prefix))
1. if (compare == o) base case, create linked list of all entries in subtree
First node of BST found matching prefix, node = root node of subtree
traverse subtree tree inorder inserting at foot into linked list.
When subtree == NULL, is processed
Traverse main tree to find the first matching (root)node.
can I use matches to recurse through the base case to build the linked list or am i forced to iterate?
Is there a better way than the above to do this?