1. Engineering
  2. Computer Science
  3. problem 1 write a function called backspacecompare that takes two...

Question: problem 1 write a function called backspacecompare that takes two...

Question details

Problem 1: Write a function called backspaceCompare that takes two strings sl and s2 and evaluate them when both are typed into empty text editors. (# means a backspace character). backspacecompare should return true if the evaluated strings are equal or false if they are not equal. You should make use of the built-in java implementation of the stack data structure under java.util.Stack . (assume that the user inputs correct strings) Example 1: input : si Datastructure sissss###Fun, s2 Datastructures Iszwp###Fun Output: true Explanation: Both s1 and s2 become DataStructuresIsFun. Example 2: Output: false Explanation: s1 becomes a while s2 becomes w -Function Template--- import java.util.Stack; public class Lab3 public static void main (String[] args) string si- Dat astructure sissss###Fun; string s2- Dat astructure s1szwp###Fun; boolean ansbackspaceCompare(s1, s2); System.out.println (ans); // Should be True public static boolean backspaceCompare(String s1, String s2)1 Stack<Character s1stack new Stack<Character>(); Stack<Character» s2 stack = new Stack<Character>(); // Example of push // Example of peek // Example of pop // Example of İsEmpty stack.push(D) stack.peek() stack.pop() stack. isEmpty() // INSERT YOUR CODE HERE

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution