We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C
- Functions
- Sorting Array of Strings
- Discussions
Sorting Array of Strings
Sorting Array of Strings
Sort by
recency
|
228 Discussions
|
Please Login in order to post a comment
For people who struggles to solve the problem. Pay attention to memory leaks and invalids reads and writes.
c
the correct logic of this code
int lexicographic_sort(const char* a, const char* b) { return strcmp(a, b); }
int lexicographic_sort_reverse(const char* a, const char* b) { return strcmp(b, a); }
int sort_by_number_of_distinct_characters(const char* a, const char* b) { int count_a = 0, count_b = 0; int freq_a[26] = {0}, freq_b[26] = {0};
}
int sort_by_length(const char* a, const char* b) { int len_a = strlen(a); int len_b = strlen(b);
}
void string_sort(char** arr, const int len, int (cmp_func)(const char a, const char* b)) { for (int i = 0; i < len; i++) { for (int j = i + 1; j < len; j++) { if (cmp_func(arr[i], arr[j]) > 0) { char* temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } }
Came back only to have the same issue, my output in clion was correct, but incorrect in the online editor. I think there is a discrepency between me running it on clion and this online editor. It was fixed by changing the sort by distinct characters method to something similar to bin sort. Posting this answer because I don't think it's fair to not give a more detailed answer as to why test cases failed.