I am trying to solve a problem "find if a string has all unique characters", in different ways possible.
One way i thought was, i could store the characters in a 'list', and then sort the list, and then just pop one character and compare it with the next one, if they are same, the string has duplicates. Effectively this should give nlogn time.
But, as i see it, my list is not pushing duplicate characters. If the char is duplicate, it is not pushing it in the list. Which i am not understanding why, coz list are supposed to take any values, And that is why they have 'list::unique' function too.
Please have a look at the code, and suggest if there is any problem...
line 31 is not the main problem. (i changed it and checked again),,
As i had checked earlier while testing itself, the list is not getting the duplicate characters. I am also printing the character at 'iter', and there you can see it is omitting the duplicate characters, i dont know why....
But i specially wanted to do it using the 'list' of stl. Because i wanted to use its 'sort' function...
The algo you gave me, and the similar one that i had designed has complexity of n^2, (coz in the worst case it has to traverse n guys n times)... but with sort, it reduces to nlogn, which is quite significant...