# 10.2. Anagrams > Sort an array of strings so that all the anagrams are next to each other. Anagram: word formed by rearranging the letters of another, such as spar formed by rasp. Each word in the array should be sorted alphabetically, and then each word sorted in the array. Can start from the beginning, sort each word, and iteratively add the new sorted word to the sorted array. ```c++ const int MAX_CHAR = 26; // function to print string in sorted order void sortString(string &str) { // Hash array to keep count of characters. // Initially count of all charters is // initialized to zero. int charCount[MAX_CHAR] = {0}; // Traverse string and increment // count of characters for (int i=0; i