Question
Constraints and Assumptions: Input string is of finite size < 50. Input string cannot be empty or NULL. Input string only contains either 'a' or
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.
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"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started