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
You have just installed a SOHO router in a customer’s home and the owner has called you saying his son is complaining that Inter
emmainna [20.7K]

Answer: A. Verify the wireless connection is using the fastest wireless standard the router supports.

D. Enable QoS for the gaming applications on the router and on the son's computer.

Explanation: Verifying the wireless connection is using the fastest wireless standard the router supports will improve line of connectivity and reduce network latency hence gaming consoles communicate faster.

QoS enables the prioritizing of the volume of internet traffic on the console for high quality gaming. QoS will also enable more internet bandwidth to be channeled to the gaming console.

6 0
3 years ago
1. Fill in the blanks:
Anit [1.1K]

Answer:

<h2>a) computer software </h2>

<h2>b) flash drive</h2>

<h2>c) Latin "putare" </h2>

<h2>d) Hardware</h2>

<h2>e) software</h2>

hope it's helpful ✌

8 0
3 years ago
HELP PLEASE!!!! Which type of prototyping is most often associated with the rapid prototyping development method?
Georgia [21]

Answer:

That will be Throwaway

6 0
3 years ago
Where can I learn how you hack?​
morpeh [17]

Answer:

www.udemy.com

5 0
2 years ago
Read 2 more answers
What is the term for an element on a Webpage that contains data and procedures for how that item will react when activated
dezoksy [38]

Answer:

It is an object.  And this is because an object has the data and procedures that defines how it is going to react when it is going to be activated. The data is the details about the object, and it explains what the object actually is. And the procedures are the details of the functions that the particular objects can perform. Like for a hospital, data can be mentioning list of medication services they provide, and procedure can be like registering for any medication service, the complete process.

Explanation:

The answer is self explanatory.  

6 0
2 years ago
Other questions:
  • A windows computer is shared between several users, each with his own local user account. Each user has his own dedicated, uniqu
    9·1 answer
  • A restaurant bill comes to $28.35. Find the total cost if the tax is 6.25% and a 20% tip is left on the amount before tax.​
    6·1 answer
  • What are three ways you cite evedince
    5·2 answers
  • What two devices in a computer should be considered "black boxes," and should never be opened due to risks involving charged cap
    13·1 answer
  • Select the layer of the OSI model that is responsible for reformatting, compressing, and/or encrypting data in a way that the ap
    14·1 answer
  • Choose the term that matches the action.
    5·2 answers
  • Complete the statement using the correct term.
    10·1 answer
  • Consider a Huffman’s Algorithm that uses a variable-length encoding scheme to compress the original text: BIRTHDAY to determine
    7·1 answer
  • We begin with a computer implemented in a single-cycle implementation. When the stages are split by functionality, the stages do
    13·1 answer
  • Which of the following best explains how the Internet is a fault-tolerant system?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!