CJCoding With Joseph
15free / daySign inCreate account

Remove Adjacent Duplicates

Write a function string removeAdjacent(const string& s) that uses a stack<char> to repeatedly delete pairs of equal adjacent characters until no such pair remains, and returns whatever is left.

Example: "abbaca" — "bb" cancels leaving "aaca", then "aa" cancels leaving "ca". The test prints the returned string on its own line (see Expected Output).

If every character cancels, return the empty string; the test then prints the line (empty).

Do NOT write a main function.

Expected Output:

ca
ay
(empty)

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
STL ContainersStacks
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.