← Back to STL Containers
Question 520
Remove Adjacent Duplicates
Remove Adjacent Duplicates
Write a functionstring removeAdjacent(const string& s)that uses astack<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
Sign in to use hintsTopics:
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.