Question: Description Given a string S, a duplicate removal consists of choosing two adjacent and equal letters, and removing them. We can repeatedly make duplicate removals

Description Given a string S, a duplicate removal consists of choosing two adjacent and equal letters, and removing them. We can repeatedly make duplicate removals on S until we no longer can. Please write a program using the Stack data structure that can read in an arbitrary string entered by users, and remove all the two successively duplicate characters in the string. The program will then output the final resulting string onto screen. You may assume all input strings are in lower case. Outputs: Your results should look similar as follows.

$ java RemoveDuplicate Please enter a string: abbaca

After removing all adjacent duplicate characters, the string is: ca

$java RemoveDuplicate Please enter a string: abcddcb

After removing all adjacent duplicate characters, the string is: a

$java RemoveDuplicate Please enter a string: adddda

After removing all adjacent duplicate characters, the

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!