Sorting algorithm with anagrams implemented