Working on a project where I am supposed to read in a file chosen by user and sort the words into a structure and the number of times they occur.
My stucture is as follows:
struct wordStruct
{
string word;
int occur;
};
wordStruct StrArray[1000];
I'm currently working in a function where I first sort the words then remove the duplicates. I have been able to sort the words, but and having trouble removing duplicates. Here is what I have thus far:
Do you know hash tables? If so, it would be easier to hash the words to a unique value and then use the hash value as the index into an array. The element of the array can be a structure that stores the word and the number of occurences.
Storing it in an array would be a bit difficult as I assume you'd have/want to fix the holes caused by removing the duplicate words.
No, i'm not familiar with them still in first c++ class unfortunatley. This is how our prof told us to do it for now so I think it will work somehow but I keep getting Segmentation fault (core dumped) compiler error mssg.
LowestOne is correct. Given this is a intro class to C++ I don't think efficiency is of that importance yet so just scan the list to see if the word exists first.