Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

Students also viewed these Databases questions

Question

Explain the functions of financial management.

Answered: 1 week ago

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago

Question

Discuss the goals of financial management.

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago