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.
intlexicographic_sort(constchar*a,constchar*b){inti=0,j=0,k=0,l=0;i=strlen(a);j=strlen(b);intlen;if(j<i){len=j;}elselen=i;for(intx=0;x<len;x++){if(a[x]>b[x]){return1;}if(a[x]<b[x]){return0;}}if(i>j){return1;}return0;}intlexicographic_sort_reverse(constchar*a,constchar*b){inti=0,j=0,k=0,l=0;i=strlen(a);j=strlen(b);intlen;if(j<i){len=j;}elselen=i;for(intx=0;x<len;x++){if(a[x]>b[x]){return0;}if(a[x]<b[x]){return1;}}if(i>j){return0;}return1;}intsort_by_number_of_distinct_characters(constchar*a,constchar*b){inti=0,j=0,k=0,l=0;i=strlen(a);j=strlen(b);for(inty='a';y<='z';y++){for(intx=0;x<i;x++){if((x!=y)&(a[x]==(char)y)){k++;break;}}}for(inty='a';y<='z';y++){for(intx=0;x<j;x++){if((x!=y)&(b[x]==(char)y)){l++;break;}}}if(k>l){return1;}if(k<l){return0;}if(k==l){return(lexicographic_sort(a,b));}return0;}intsort_by_length(constchar*a,constchar*b){inti=0,j=0;i=strlen(a);j=strlen(b);if(i>j){return1;}if(i<j){return0;}if(i==j){return(lexicographic_sort(a,b));}return0;}voidswap_arr(char**x,char**y){char*temp=*x;*x=*y;*y=temp;}voidstring_sort(char**arr,constintlen,int(*cmp_func)(constchar*a,constchar*b)){char*buff;inti,j;intswapped;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 breakif(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 →