1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Licemer1 [7]
3 years ago
13

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 : s1 = "Datastructure sissss###Fun", s2 = "Datastructures Iszwp###Fun"
Output: true
Explanation: Both s1 and s2 become "DataStructuresIsFun".
Example 2:
Input : S = "abc##, T = "wc#d#"
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 s1 = "Dat astructure sissss###Fun";
String s2 = "Dat astructure s1szwp###Fun";
boolean ans = backspaceCompare(s1, s2);
System.out.println (ans); // Should be True
}
public static boolean backspaceCompare(String s1, String s2) {
Stack s1 stack = new Stack();
Stack s2 stack = new Stack();
// Example of push stack.push("D")
// Example of peek stack.peek()
// Example of pop stack.pop()
// Example of İsEmpty stack. isEmpty()
// INSERT YOUR CODE HERE
}
}
Computers and Technology
1 answer:
Andrej [43]3 years ago
6 0

Answer:

Go to explaination for the program code

Explanation:

import java.util.Stack;

public class Lab3 {

public static void main(String[] args) {

String s1="DataStructuresIssss###Fun";

String s2="DataStructuresIszwp###Fun";

boolean ans=backspaceCompare(s1,s2);

System.out.println(ans);

/*String s1="abc##";

String s2="wc#d#";

boolean ans=backspaceCompare(s1,s2);

System.out.println(ans);*/

}

public static boolean backspaceCompare(String s1, String s2) {

Stack<Character> s1_stack=new Stack<Character>();

Stack<Character> s2_stack=new Stack<Character>();

//backspaceCount is a variable to count back space

int backspaceCount=0;

//logic is that if '#' encountered we are putting pop else push

for(int i=0;i<s1.length();i++){

if(s1.charAt(i)=='#'){

backspaceCount++;

s1_stack.pop();

}

else

{

s1_stack.push(s1.charAt(i));

}

}

//this all is for s2 string

for(int i=0;i<s2.length();i++){

if(s2.charAt(i)=='#') s2_stack.pop();

else s2_stack.push(s2.charAt(i));

}

//here is the main logic first we are adding based upon # means we pop up the string while adding the string if any # character found

//here we are checking from the end using pop condition both are not mathing then we are returning false

for(int i=0;i<s1.length()-2*backspaceCount;i++){

if(s1_stack.pop()!=s2_stack.pop()) return false;

}

return true;

}

}

You might be interested in
Which of the following is an example of a currency Number format in Excel?
Elena L [17]

$21.08 is an example of a currency Number format in Excel

<u>Explanation:</u>

For items like currency, one can format numbers in cells in Excel.

To view all possible number formats, click the Dialog Box Launcher attached to Number on the Home tab in the Number group.

In the Format Cells dialog box, in the Category list, click Currency or Accounting.

In the Symbol box, tick the currency symbol.

In the Decimal places box, insert the number of decimal places.

Employed for common financial values and presents the default currency figure with quantities.

Ctrl+Shift+$ is a shortcut to represent currency values.

8 0
3 years ago
if you were writing an essay about the major rivers of America which illustration would be the most helpful to your reader ​
Dmitrij [34]

Answer:A map

Explanation: (╹◡╹)

4 0
3 years ago
ROM stores data as you search the internet to help increase the speed of your computer.
olasank [31]

Answer:  

The answer to the following question is "false".  

Explanation:  

In computer science, ROM stands for read-only memory. ROM is an electronic device that stores data. It is non-volatile which means that the data is saved even if the part drops power. Once information has been signed into a ROM, it cannot be removed and can only be read.  So the answer to this question is "false".

5 0
3 years ago
A diminished triad can be indicated by
natka813 [3]

A  diminished triad can be indicated by A lower-case Roman numeral and °.

<h3>How do you Know a diminished triad?</h3>

In any diminished triad, the middle and top two notes of the chord are known to be the flattened and shown by the symbol "o" or "dim."

Therefore, A  diminished triad can be indicated by A lower-case Roman numeral and °.

See options from below

A diminished triad can be indicated by:

A) A lower-case Roman numeral and °.

B) A lower-case Roman numeral and +.

C) An upper-case Roman number and °.

Learn more about triad from

brainly.com/question/4951751

#SPJ11

3 0
1 year ago
College
stiks02 [169]

Answer:

Read Technical Books. To improve your technical skills and knowledge, it's best to read technical books and journals. ...

Browse Online Tutorials. ...

Build-up online profile. ...

Learn new Tools. ...

Implement what you learned. ...

Enrich your skillset. ...

Try-out and Apply.

3 0
3 years ago
Other questions:
  • in what way do rules and laws created to address public problems affect individuals groups and business
    13·1 answer
  • Before using the data type string, the program must include the header file ____.
    6·1 answer
  • What is the QOS model?
    6·1 answer
  • CodeHS 3.4.5. What is the code for four colored triangles.
    8·1 answer
  • When a computer is suffering from a virus, you can use a compiler to help remove the virus. True or false?
    13·1 answer
  • What can provides access to the only menu in office 2007​
    13·1 answer
  • You are a network administrator for your company. The network consists of a single Active Directory domain. All servers run Wind
    7·1 answer
  • The return value is a one-dimensional array that contains two elements. These two elements indicate the rows and column indices
    12·1 answer
  • Can someone pls do a toradora,Mha or princess jellyfish rp I'm open for anyother rp's
    11·2 answers
  • There are a wide variety of nonsampling errors that can occur during data collection including the first type, ________.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!