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
FromTheMoon [43]
3 years ago
13

Describe how to scan a stack S containing to see if it contains a particular value x using only a queue Q and a constant number

of reference variables. The stack contains n values and Q is initially empty. When the process finishes, the elements of S must be in their original order. [Preferred Language in C++]
Computers and Technology
1 answer:
disa [49]3 years ago
4 0

Answer:

#include <iostream>

#include <stack>

#include <queue>

using namespace std;

bool checkfor(stack<int> &stk, int x){

 

   queue<int> q;

   bool flag = false;

   while(!stk.empty()){

       int p = stk.top();

       stk.pop();

       if(p == x){

           flag = true;

       }

       q.push(p);

   }

 

   while(!q.empty()){

       stk.push(q.front());

       q.pop();

   }

   while(!stk.empty()){

       q.push(stk.top());

       stk.pop();

   }

 

   // from queue to stack

   while(!q.empty()){

       stk.push(q.front());

       q.pop();

   }

 

   return flag;

 

}

int main(){

 

   stack<int> stk;

   // pushing data to stack

   stk.push(1);

   stk.push(3);

   stk.push(43);

   stk.push(2);

   stk.push(5);

 

   cout<<(checkfor(stk, 5)?"Found": "Not Found")<<'\n';

   cout<<(checkfor(stk, 10)?"Found": "Not Found")<<'\n';

 

   return 0;

}

Explanation:

  • Check the top of stack for relevant value and insert that into queue.
  • Take value from front of queue and push it to stack after the stack is empty.
  • Now empty queue and push values to stack.
You might be interested in
What is a zerø-day exploit? No go.ogle &gt;:(
Igoryamba

Answer:A zero-day vulnerability is a vulnerability in a system or device that has been disclosed but is not yet patched. An exploit that attacks a zero-day vulnerability is called a zero-day exploit.

Explanation:

6 0
2 years ago
The final step in the object-oriented design (ood) process consists of developing the?
kenny6666 [7]

The final step in the object-oriented design (OOD) process consists of developing the <u>package diagrams.</u>

<u></u>

In the field of Computer studies, object-oriented design (OOD) can be described as a design method in which a proper system of interacting objects is planned for making a computing system or software.

The final step of an object-oriented design (OOD) involves the development of package diagrams. Package diagrams are structures or diagrams that are used for representing the model elements. The model elements are shown as packages in this kind of diagram.

Package diagrams are the final step of an object-oriented design process because they help to provide a visual idea of the overall proposed design.

To learn more about object-oriented designs, click here:

brainly.com/question/13383471

#SPJ4

5 0
2 years ago
To be useful for most household applications, DC voltage is?please <br>​
satela [25.4K]

Answer: To be useful for most household applications, DC voltage is passed through a step-down transformer.

Explanation: Voltage coming through AC or DC outlets is typically far too high for most household appliances to handle, so the current is passed through a step-down transformer to reduce the voltage to a usable level.

3 0
3 years ago
Which changes the natural world? <br> technology <br> science <br> prototypes <br> feedback
Gelneren [198K]
It would be technology,
5 0
3 years ago
Write a program that has an input as a test score, and figures out a letter grade for that score, such as "A", "B", "C", etc. ac
Marizza181 [45]

Answer:

The program in csharp for the given scenario is shown.

using System;

class ScoreGrade {

static void Main() {

//variables to store score and corresponding grade

double score;

char grade;

//user input taken for score

Console.Write("Enter the score: ");

score = Convert.ToInt32(Console.ReadLine());

//grade decided based on score

if(score>=90)

grade='A';

else if(score>=80 && score<90)

grade='B';

else if(score>=70 && score<80)

grade='C';

else if(score>=60 && score<70)

grade='D';

else

grade='F';

//score and grade displayed  

Console.WriteLine("Score: "+score+ " Grade: "+grade);

}

}

OUTPUT1

Enter the score: 76

Score: 76 Grade: C

OUTPUT2

Enter the score: 56

Score: 56 Grade: F

Explanation:

1. The variables to hold the score and grade are declared as double and char respectively.

int score;

char grade;

2. The user is prompted to enter the score. The user input is not validated and the input is stored in the variable, score.

3. Using if-else-if statements, the grade is decided based on the value of the score.

if(score>=90)

grade='A';

else if(score>=80 && score<90)

grade='B';

else if(score>=70 && score<80)

grade='C';

else if(score>=60 && score<70)

grade='D';

else

grade='F';

4. The score and the corresponding grade are displayed.

5. The program can be tested for different values of score.

6. The output for two different scores and two grades is included.

7. The program is saved using ScoreGrade.cs. The .cs extension indicates a csharp program.

8. The whole code is written inside a class since csharp is a purely object-oriented language.

9. In csharp, user input is taken using Console.ReadLine() which reads a string.

10. This string is converted into an integer using Convert.ToInt32() method.

score = Convert.ToInt32(Console.ReadLine());

11. The output is displayed using Console.WriteLine() or Console.Write() methods; the first method inserts a line after displaying the message which is not done in the second method.

12. Since the variables are declared inside Main(), they are not declared static.

13. If the variables are declared outside Main() and at the class level, it is mandatory to declare them with keyword, static.

6 0
3 years ago
Other questions:
  • Write a program that checks for car mileage. if the mileage is greater than 100000, display "clunker!". if not, display "buy it!
    7·1 answer
  • 1. Write a program to prompt the user to enter a single character and respond back whether or not the character is valid dna. 2.
    12·1 answer
  • manufacturers are making an effort to build energy-efficient computers and use recyclable cases and packaging true or false
    10·1 answer
  • How to tell if motherboard has bluetooth?
    8·1 answer
  • Which type of computer network ensures high quality​
    9·1 answer
  • What does the FixedUpdate loop do? Why do developers use it?
    14·1 answer
  • Which symbol is at the beginning and end of a multiline comment block? ### &amp;&amp;&amp; %%% """
    14·1 answer
  • write the definition of a class clock. the class has no constructors and one instance variable of type int called hours.
    12·1 answer
  • A ____________ protocol is software that provides or facilitates a connection in which no information is retained by either send
    13·1 answer
  • What is the significance of the scientific method?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!