Generating anagram using stack