Stacks Flashcards

1
Q

What is a stack?

A

A data structure that follows LIFO (Last In, First Out).

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

How do you implement a stack using a list in Python?

A

stack = []

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

How do you push an element onto a stack?

A

stack.append(item)

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

How do you pop an element from a stack?

A

stack.pop()

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

What happens if you pop from an empty stack?

A

It raises an IndexError unless handled properly.

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