Given an array of strings arr[] of size N, the duty is to kind the strings in Lexicographical order.
Examples:
Enter: arr[] = {“batman”, “bat”, “apple”}
Output:
apple
bat
batman
Clarification:
The lexicographical order of string is “apple”, “bat”, “batman”Enter: arr[] = {“geeks”, “for”, “geeksforgeeks”}
Output:
for
geeks
geeksforgeeks
Strategy:
The array will be sorted in growing order by evaluating ASCII values of the leftmost character which might be totally different among the many strings.
To kind the strings we are able to use the inbuilt kind() perform. The perform types the string in lexicographical order by default.
Under is the implementation for the above strategy:
C++
|
Time Complexity: O(N * logN * M), the place M is the typical size of the strings
Auxiliary House: O(1)