Re: Program to find occurences of a word in a file
On Nov 20, 6:44 am, Sohail Somani <soh...@taggedtype.net> wrote:
On Mon, 19 Nov 2007 20:29:38 -0800, Neehar wrote:
I was asked to do this without sorting. Is there a better way to do
This could eliminate the map based solutions as map does an
implicit sort on insertion.
Sort of, and of course, std::map.
I would think a hash based data structure might do, like
std::unsorted_map, from the next version of the standard?
Another alternative, if you're going to implement the underlying
data structure yourself, would be a trie. Still, I'd start with
std::map< Word, int >. The real problem would be defining Word;
we've not been given enough information to do this. (If the
definition is just the usual meaning in non-technical English,
then I don't think the problem is solvable. On the other hand,
just any sequence of non-white space characters, separated by
white space, makes the solution so trivial it certainly wouldn't
be asked with 30 minutes to solve it.)
James Kanze (GABI Software) email:firstname.lastname@example.org
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34