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]
3 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]3 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
If nobody buys a ticket to a movie, do they still show it?
Serga [27]

It would depend on the movie and the theater policy.....

Hope this helps have a good day

3 0
3 years ago
7.6 lesson practice edhesive
grigory [225]
There is a equal amount I guess free points for me
5 0
2 years ago
Read 2 more answers
Write the prototype for a function named showSeatingChart that will accept the following two-dimensional array as an argument. c
barxatty [35]

Answer:

See explaination

Explanation:

void showSeatingChart(string seatingChart[20][40], const int ROWS, const int COLS){

for(int i = 0;i<ROWS;i++){

for(int j = 0;j<COLS;j++){

cout<<seatingChart[i][j]<<" ";

}

cout<<endl;

}

}

4 0
3 years ago
What's the component of the hardware?​
melisa1 [442]
Some component of the hardware are central processing unit (CPU), monitor, mouse, keyboard, computer data storage, graphics card, sound card, speakers and motherboard.

I’m sure theirs more but here’s so. Hope this helps!
7 0
2 years ago
Read 2 more answers
How are gems and precious metals similar?
Ierofanga [76]
The answer would be d they are both rare and valuable minerals
7 0
3 years ago
Read 2 more answers
Other questions:
  • Consider the following classes:
    8·1 answer
  • 10 facts about turbines
    11·2 answers
  • This toolbar can be used to change the way the text in your presentation looks. Drawing
    5·2 answers
  • A.<br> Post-It note<br> b.<br> notebook<br> c.<br> tutor<br> d.<br> spell check
    14·1 answer
  • Write the definition of a function reverse, whose first parameter is an array of integers and whose second parameter is the numb
    15·1 answer
  • True or False The two types of general construction projects are residential for homes or dwellings and commercial for a commerc
    7·1 answer
  • Encryption is an important topic in math and computer science. It keeps your personal information safe online.
    6·1 answer
  • This is a tableware use to serve the main dish
    11·1 answer
  • How to play Drinkopoly game?
    12·1 answer
  • Html is a markup language that lets you identify common sections of a web page
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!