To sort a given array of strings into lexicographically increasing order or into an order in which the string with the lowest length appears first, a sorting function with a flag indicating the type of comparison strategy can be written. The disadvantage with doing so is having to rewrite the function for every new comparison strategy.
A better implementation would be to write a sorting function that accepts a pointer to the function that compares each pair of strings. Doing this will mean only passing a pointer to the sorting function with every new comparison strategy.
Given an array of strings, you need to implement a function which sorts the strings according to a comparison function, i.e, you need to implement the function :
You also need to implement the following four string comparison functions:
to sort the strings in lexicographically non-decreasing order.
to sort the strings in lexicographically non-increasing order.
to sort the strings in non-decreasing order of the number of distinct characters present in them. If two strings have the same number of distinct characters present in them, then the lexicographically smaller string should appear first.
to sort the strings in non-decreasing order of their lengths. If two strings have the same length, then the lexicographically smaller string should appear first.
You just need to complete the function string\_sort and implement the four string comparison functions.
No. of Strings
Total Length of all the strings
You have to write your own sorting function and you cannot use the inbuilt function
The strings consists of lower-case English Alphabets only.
The locked code-stub will check the logic of your code. The output consists of the strings sorted according to the four comparsion functions in the order mentioned in the problem statement.