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
Darina [25.2K]
4 years ago
6

What is the output of the following code? stackList stack; int x, y; x = 2; y = 3; stack.push(8); stack.push(x); stack.push(x +

5); y = stack.top(); stack.pop(); stack.push(x + y); x = stack.top(); stack.pop(); cout << "x = " << x << endl;
Computers and Technology
1 answer:
Sunny_sXe [5.5K]4 years ago
3 0

Stack is LIFO data structure (Last In First Out) where the last element entered in stack will be the last one to be out of stack. It has three operations: push() : used to insert an element in stack, pop() : used to delete an element from the stack, top() : used to return the top of the stack i.e. the newest member of the stack. All these operations will take place at the top.

<u>Explanation:</u>

Now, looking at the program, x and y are initialized the values of 2 and 3 respectively. The stack pushes 8 onto the stack making it the first member of the stack. Then the value of x which is 2 is pushed onto the stack. Next, (x+5) = (2+5) = 7 is pushed onto the stack.

Pop() is used to delete hence 7 is popped out from the stack. top() is assigned to y which is 2 in this case and again 2 is popped out from the stack. Now, (x+y) = (2+2) = 4 is pushed onto the stack. And the top() is assigned to x which is 4. 4 is again popped out from the stack. Hence the value of x is 4.

You might be interested in
You are setting up a home network for your friend. She has students visiting her home regularly for lessons and wants to provide
SCORPION-xisa [38]

Answer:

A guest network

Explanation:

3 0
3 years ago
The first row of a table is often called the _____ row.
satela [25.4K]

ANSWER:

The first row of a table is often called the header row.

~batmans wife

7 0
3 years ago
Read 2 more answers
What is live ware in relation to computer​
Zarrin [17]

Answer:

It is a slang term used to denote people using (attached to) computers.

6 0
3 years ago
A relative path name defines a path from_________________________ Select one: a. from the UFD (user file directory) b. the curre
lorasvet [3.4K]

Answer:

(b)  the current directory

Explanation:

A path is the location or route to a particular file or folder in an operating system. This path is always unique and can either be relative or absolute.

A relative path name of a file defines the path to the file from the current or present working directory.

An absolute path name of a file defines the path to the file from the root directory. This path gives a complete descriptive path to a file from the start of the actual file system of the operating system.

4 0
3 years ago
Let S be an NP-complete problem and Q and R be two other problems not known to be in NP. Q is polynomial time reducible to S and
levacccp [35]

Answer:

B. R is NP Hard

Explanation:

Given:

S is an NP complete problem

Q is not known to be in NP

R is not known to be in NP

Q is polynomial times reducible to S

S is polynomial times reducible to R  

Solution:

NP complete problem has to be in both NP and NP-hard. A problem is NP hard if all problems in NP are polynomial time reducible to it.

Option B is correct because as given in the question S is an NP complete problem and S is polynomial times reducible to R.

Option A is not correct because R is not known to be in NP

Option C is not correct because Q is also not known to be in NP

Option D is not correct because Q because no NP-complete problem is polynomial time reducible to Q.

5 0
3 years ago
Other questions:
  • Jesse is writing a physics quiz about the motion of a roller coaster cart. He has a clip art illustration of a cart rolling hori
    9·2 answers
  • How can I get more Gems in the game {Fashion Empire} through a Fire kindle?
    15·2 answers
  • Which process improves the life of a computer?
    11·1 answer
  • The World Wide Web is a program that allows you to search for information on the Internet.
    11·1 answer
  • If num is an int which expression always evaluates to true if num holds an odd number
    15·1 answer
  • Jenny, a programmer, uses Microsoft Excel 2016 to generate data required for the programs she develops. She uses various functio
    10·1 answer
  • During project management, who executes tasks and produces the deliverables as stated in the project plan and as directed by the
    9·1 answer
  • The four compass points can be abbreviated by single-letter strings as "N", "E", "S", and "W". Write a function turn_clockwise t
    15·1 answer
  • Is windows CUI operating system??<br><br><br>What is the main purpose of folder ????<br><br><br>​
    15·1 answer
  • List three variables that could be used in creating a model that determines the best day to plant corn in a given location. 30 p
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!