Question: Answer The Following Multiple Choice Questions And Choose the Correct Answer (1-4). The operation that adds a new item to a stack is... Question 1

Answer The Following Multiple Choice Questions And Choose the Correct Answer (1-4).

The operation that adds a new item to a stack is...

Question 1 options:

1.

push

2.

insert

3.

pop

4.

remote

Question 2:

A stack is one kind of ____ data structure.

Question 2 options:

1.

FIFO

2.

LIFO

3.

FINO

4.

all of the above

Question 3:

When you run the following code:

stack s; // the stack is empty when first created s.push(42); s.push(73); assert(!s.empty()); // Assert A s.pop(); s.push(23); assert(!s.empty()); // Assert B s.pop(); assert(!s.empty()); // Assert C

Question 3 options:

1.

assert A will fail

2.

assert B will fail

3.

assert C will fail

4.

it will finish without any of the asserts failing

Question 4:

When you run the following code:

stack s; // the stack is empty when first created s.push(0); s.push(1); s.push(2); assert(s.size() == 3); // Assert A s.pop(); assert(!s.empty()); // Assert B int n = s.top(); for (int i = 0; i < n; i++) { s.pop(); } assert(s.top() == 1); // Assert C

Question 4 options:

1.

assert A will fail

2.

assert B will fail

3.

assert C will fail

4.

it will finish without any of the asserts failing

Question 5:

The stack::top method returns by reference. One reason for this is that...

Question 5 options:

1.

it wouldn't be possible to return the item by value

2.

it avoids making a copy of the item being returned

3.

it means the item will continue to exist if the stack is destroyed

4.

the caller would otherwise have to free the item manually

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!