So I am given a string:

x = "llo";

I have a string array with a list of words:

words{}={"hi", "bye", "lol"};

I have to compare x to each of the strings in the array to determine what x is if it is 'unscrambled'.

What is the best possible way to do this?

The "best" algorithm depends on the nature of the input and the evaluation metric for "best". Is it only one x that will be compared etc.

It sounds like you have words at compile time. If that is the case, then use template meta-programming and create an alphabetical list of alphabetical entries to search against. Use the boost::mpl http://www.boost.org/doc/libs/1_40_0/libs/mpl/doc/index.html to do that and then use runtime polymorphism to find your target set. That would be very very fast (CPU) time.

Sorry for the useless reply but you haven't shown much effort with your question. What have your thought of and why do you like and more importantly why don't you like what you have prototyped/coded?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.