Sorting Array of Strings: Void String - Sort (Char Arr, Const Int CNT, Int ( CMP - Func) (Const Char A, Const Char B) )
Sorting Array of Strings: Void String - Sort (Char Arr, Const Int CNT, Int ( CMP - Func) (Const Char A, Const Char B) )
Strings
Depending on certain circumstances, we may want 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.
We could make a sorting function and pass the function a flag telling it which comparison strategy to use,
but that would mean that whenever we invented a new comparison strategy, we would have to define a
new code or flag value and rewrite the sorting function.
But, if we observe that the final ordering depends entirely on the behaviour of the comparison function, a
better implementation would be if we write our sorting function to accept a pointer to the function which
we want it to use to compare each pair of strings.
Making it sort in a different order, according to a different comparison strategy, will then not require
rewriting sorting at all, but instead will just involve passing it a pointer to a different comparison function.
Given an array of strings, you need to implement a string_sort function which sorts the strings according
to the following different criterion.
void string_sort(char **arr,const int cnt, int (*cmp_func)(const char* a, const char* b)){
an array of strings :
3. 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.
Input Format
You just need to complete the function and implement the four string comparison
functions.
Constraints
Sample Input 0
4
wkue
qoi
sbv
fekls
Sample Output 0
fekls
qoi
sbv
wkue
wkue
sbv
qoi
fekls
qoi
sbv
wkue
fekls
qoi
sbv
wkue
fekls