0

Can someone please help me with my homework? It’s only my second week in the class and we have not reviewed this at all!

You can instantiate (create) a C++ string on the stack like so: string str = "babbaa"; which consists of an array of 6 elements of type char: {'b','a','b','b','a','a'}; You have a C++ string of finite length consisting of only 'a' and 'b's in it. Write the following function to separate all of the 'a' and 'b' in the string so that all 'a' appear before 'b' in it: string separateLetters(string input); The above sorted string becomes, for example: cout << separateLetters("babbaa"); // outputs "aaabbb" Examples: Input: "abbbbbbbbaaaaaaa" Output: "aaaaaaaabbbbbbbb" Input: "a" Output: "a" Input: "bb" Output: "bb" Input: "ab" Output: "ab" Input: "ba" Output: "ab" Constraints and Assumptions: Input string is of finite size < 50. Input string cannot be empty or NULL. Input string only contains either 'a' or 'b' English lower-case alphabets, nothing else. Do NOT use any existing C++ sorting library for this problem.

14th Mar 2019, 11:02 PM
Manuel Jimenez
1 Respuesta
0
https://code.sololearn.com/cJ25bE3u1x31/#cpp You should try your homework. Post your code and then to be helped by the forum.
15th Mar 2019, 7:26 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar