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:

The first recursion takes place to find the first node matching the prefix "ne", this I consider as the root of a new tree, a tree containing mostly phrases that match the prefix.

The second recursion is an inorder traversal of the subtree to insert the phrases that match the prefix into a list

The idea behind the algorithm is to isolate the part of the entire tree containing phrases with the same prefix, and then move inorder through the sub_tree inserting only the matches into a list.

The only time matches needs to return a value is when the list has been filled with phrases that have the smae prefix from the sub_tree

The base case for recursion is when I search and find the first node in the tree with a similar prefix. This as far as I see is the root of a subtree with phrases of similar prefix.

I then move to recurse though the subtree inserting only the phrases that match the prefix into the list.
The insert into list function returns the complete list, the matches function then returns the list to the caller.