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.
int sort_by_number_of_distinct_characters(const char* a, const char* b) {
int i=0, j=0, k=0, l=0;
i = strlen(a);
j = strlen(b);
for(int y='a'; y<='z'; y++){
for(int x=0; x
}
}
void string_sort(char** arr,const int len,int (cmp_func)(const char a, const char* b)){
char *buff;
int i, j;
int swapped;
for (i = 0; i < len - 1; i++) {
swapped = 0;
for (j = 0; j < len - i - 1; j++) {
if (((*cmp_func)(arr[j],arr[j+1]))) {
swap_arr(&arr[j], &arr[j + 1]);
/* buff = arr[j];
arr[j] = arr[j+1];
arr[j+1] = buff;*/
swapped = 1;
}
}
// If no two elements were swapped
// by inner loop, then break
if (swapped == 0)
break;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sorting Array of Strings
You are viewing a single comment's thread. Return to all comments →
int lexicographic_sort(const char* a, const char* b) { int i=0, j=0, k=0, l=0; i = strlen(a); j = strlen(b); int len;
return 0; }
int lexicographic_sort_reverse(const char* a, const char* b) { int i=0, j=0, k=0, l=0; i = strlen(a); j = strlen(b); int len; if(j
return 1;
}
int sort_by_number_of_distinct_characters(const char* a, const char* b) { int i=0, j=0, k=0, l=0; i = strlen(a); j = strlen(b); for(int y='a'; y<='z'; y++){ for(int x=0; x } }
}
int sort_by_length(const char* a, const char* b) { int i=0, j=0; i = strlen(a); j = strlen(b); if (i>j){ return 1;} if (i
}
void swap_arr(char** x, char** y){ char *temp = *x; *x = *y; *y = temp; }
void string_sort(char** arr,const int len,int (cmp_func)(const char a, const char* b)){ char *buff;
}