![]() |
| ||
| word count Im trying to count the frequency of words from a file and cant seem to get it to work. My frequency function recognizes the word is there but doesnt return a count for each word yet. The text file would just hold a bunch of random words...please help. #include <string> |
| ||
| Re: word count I'am sure there is an error..Not only failed to display the freakword count.. |
| ||
| Re: word count > void main() Has nobody mentioned that main returns in in your previous 60 messages? Or did you just ignore them. Where do you - set frequency to zero? - determine that the word is already in the tree, and thus increment the frequency > else(start->item==freakword); I'd be surprised if this even compiles. You say you've run it, is this your actual code? |
| ||
| Re: word count You have too many nodes. You want one node per UNIQUE word, not one node per word. I would rename your class to word or node. You should have one tree and several nodes. You don't want to name something "tree" if there is one "tree" per word, in my opinion. If you have something called tree, make sure there is only one of them. void insert(mytree*& start, string aword) Nowhere do you compare the value of item to aword to see if they are equal and doing something if they are. You should be adjusting frequency as you insert, not later. New words should have a frequency of 1. Words already in the tree should have their frequencies incremented. Also, I don't think you can use < with strings. String isn't an ordinal type. Consider using compare if you are trying to alphabetize here: http://www.cplusplus.com/reference/s...g/compare.html class node class tree |
| ||
| Re: word count yes this does run, and setting frequency to zero and determining if a word is already in the tree then incrementing it, is what I need help on. |
| ||
| Re: word count Quote:
The naming of the struct mytree threw me. You can keep the single class if you like and call it TreeOfWords as you have it. There's no need to have a node class with an insert method. You can keep the insert method in TreeOfWords like you have it. Keeping node as a struct with no methods will work. But rename it. I'd get rid of the frequency methods. Handle adjusting frequency in insert. Again, don't create a new word if the word already exists in the tree. Just increment frequency in that case. edit: I had to change void main to int main to get it to run. Salem is right. Change it even if your compiler lets you get away with it. |
| ||
| Re: word count Just a sample..Easy way!!.. // member of TreeofWords |
| All times are GMT -4. The time now is 4:45 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC