return first non repeating character in a string
- by Amm Sokun
I had to solve this question in which given a string, i had to return the first non repeating character present in the string.
I solved it using hashtable and wrote a method which takes a constant reference to the string and returns the first non repeating character. However, when there is no non repeating character present in the string, i return -1 and in the main program i check as follows
char c = firstNonRepeating( word );
if (static_cast<int> (c) == -1)
cout<<"no non repeating character present\n";
else
cout<<c<<endl;
is that the correct way to return -1 when required character is not present?