0

Write a C program for string sort

Take a string composed of both lowercase and uppercase letters and sort it in such a manner such that the uppercase and lowercase letter comes in an alternate manner but in sorted way

30th Aug 2017, 6:49 PM
Shraddha Bhangale
Shraddha Bhangale - avatar
2 Respostas
+ 1
if you mean that "GfDcBa" should be "aBcDfG" then the answer is to make a comparator function and add it as a third parameter to the pre-defined sort function in C++.. it should be something like this: sort(str.begin(),str.end(),compFunc); P.S. parameters of sort I wrote before is for C++ strings.. if you want to use C not C++ you should replace the parameters 😁😁
31st Aug 2017, 8:16 AM
Nour Alhadi Mahmoud
Nour Alhadi Mahmoud - avatar
- 1
HI . if you want a c++ program then my friend Nour give you the code. BUT , this code doesn't fit c program you have to use the qsort() function like this: int cmp(char a,char b){ return a<b; } coid main(){ char *str; // what ever your code is int sz = sizeof(str); qsort(str,sz,4,cmp); } i didn't understand what do you mean with upper and lower case letter should alternative but i think you can store a string for lowercase letter and another one for uppercase letter and sort every one alone and then merge them as you want. GOOD LUCK WITH C LANGUAGE.
4th Sep 2017, 8:06 PM
mhamed resli
mhamed resli - avatar