The Datatype of Stacks Flashcards

1
Q

What is the LIFO principle?

A

The LIFO principle stands for “Last in, First out.” It means that the last item added to a stack is the first one to be removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the “push” operation do?

A

The “push” operation adds an item to the top of the stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the “top” operation do?

A

The “top” operation returns the item at the top of the stack without removing it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the “pop” operation do?

A

The “pop” operation removes the item at the top of the stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the main application of stacks in compilers?

A

The main application of stacks in compilers is for method calls. Stacks are used to keep track of the order in which methods are called so that they can be returned in the correct order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens when an element is pushed onto a stack?

A

When an element is pushed onto a stack, it leads to a “bigger” stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can a stack become too large to handle?

A

Yes, a stack can become too large to handle if there is not enough memory left.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens when there is not enough memory left to push an element onto a stack?

A

When there is not enough memory left to push an element onto a stack, it leads to an “error” message.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the potential mistakes that can occur when using a stack of limited size?

A

The potential mistakes that can occur when using a stack of limited size are pushing an element on a full stack, calling an empty stack with the “top” or “pop” operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can a programmer signal that these mistakes have not appeared in a stack’s history?

A

A programmer can use a boolean variable called “errorFree” to signal that these mistakes have not appeared in a stack’s history.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the initial value of the “errorFree” variable?

A

The initial value of the “errorFree” variable is true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What should happen to the “errorFree” variable if an error occurs?

A

If an error occurs, the “errorFree” variable should be set to false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly