kinda random question.

Status
Not open for further replies.

Matted Fewl

Seniorius Lurkius
28
I'm wondering if you guys could give me some ideas on how to tackle this problem. I am trying to do the following:

Say I have a text file, like this for example

Pigs and Cows
Are Fat. Porsche is
a nice car. blahblah, you get the point. Just random sentences. Now I want to do the following:

1. Create a vector name of 26 binary trees for the letters of the alphabet. Would it have to be char or string, or would it matter, since it would just point to the appropriate tree?

Like such, vector<char?string?> name(26); //isnt that how you declare a set size?

name[0] will take all the words beginning with A
name[1] will take B
name[2] will take C, etc, etc....

So if we read in Dogs it will see the D and insert it into the binary tree which name[3] points to. This making sense so far? So read in the word, get the first letter, check the appropriate binary tree, if its not found, insert it. Once your done, display all the words in alphabetic order.

Now, I get the searching and insertion ideas in trees. But how do you make it specific for the particular cell in the vector? For instance, it reads in an A, then it goes to name[0] and reads through that tree which is attached to name[0]. Would you need a name[0]->next or something to attach the tree to the cell? Does this make any sense? Thanks guys
 

Stardog

Ars Tribunus Militum
2,951
Now I want to do the following:

1. Create a vector name of 26 binary trees for the letters of the alphabet. Would it have to be char or string, or would it matter, since it would just point to the appropriate tree?

BIG EDIT: Oh yeah, I see what you're saying about the binary trees. Yeah, that'll work. Eech tree's root node will be stored in your, uh, 'alphabet vector'. No need to store the actual letter, it's enough to know that B is the second letter of the alphabet and so on. Actually, your ASCII table already knows that ;)

Each node of the tree will store a character string as it's key field. You do know that each tree node has pointers to the left and right child nodes, right? There is no 'next' pointer in a binary tree ADT implementation. Um, how are you with recursion?

[This message was edited by Stardog on December 07, 2001 at 14:56.]
 

Matted Fewl

Seniorius Lurkius
28
You do know that each tree node has pointers to the left and right child nodes, right? There is no 'next' pointer in a binary tree ADT implementation. Um, how are you with recursion?
Ya, I know trees use left and right children. Recursion is fine.
This is screaming "trie" at me.
Umm.......huh?

I guess I am confused about incorporating a vector in the tree. Like where that fits in. Thanks for replies
 

Stardog

Ars Tribunus Militum
2,951
The vector isn't in the tree. The tree is in the vector. Or rather, the root nodes of each of your trees are stored as elements in a vector of length 26. Like this:
code:<HR>
Code:
struct TREENODE { 
    TREENODE*   left;
    TREENODE*   right; 
    char        keyString[MAX_WORD_SIZE];
}<P>
#define NUM_LETTERS   26
TREENODE* treeArray[NUM_LETTERS];
Where each element of treeArray is the root node of a tree populated with words starting with the corresponding letter.
 
Status
Not open for further replies.