Question: You can instantiate (create) a C++ string on the stack like so: string str = babbaa; which consists of an array of 6 elements of

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!