I am writing code for a question which is: Write a method to sort an array of strings so that all the anagrams are next to each other. If my container is vector, it will be
You can use sort() for an array. Pointers act as iterators.
sort()
Example:
#include #include #include using namespace std; int main() { string arr[5]={"BBB","AAA","CCC","FFF", "EEE"}; sort(arr,arr+5); for(string i: arr) { cout << i << endl; } }
and the output is:
AAA BBB CCC EEE FFF