2.3.1 stacks and queues Flashcards

1
Q

QUEUES

A

Queues is a type of list where data is inserted at one end and retrieved from the other end.

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

FIFO

A

Queues are known as FIFO data structure, first in first out!

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

STACK

A

stack is a list which is limited to only allow data to be inserted and retrieved from the same end.

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

LIFO

A

stacks are known as last in first out!

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

STACK coding

A

stack = []

Push
stack.append(‘A’)
stack.append(‘B’)
stack.append(‘C’)
print(“Stack: “, stack)

Pop
element = stack.pop()
print(“Pop: “, element)

Peek
topElement = stack[-1]
print(“Peek: “, topElement)

isEmpty
isEmpty = not bool(stack)
print(“isEmpty: “, isEmpty)

Size
print(“Size: “,len(stack))

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

QUEUES coding

A

queue = []

Enqueue
queue.append(‘A’)
queue.append(‘B’)
queue.append(‘C’)
print(“Queue: “, queue)

Dequeue
element = queue.pop(0)
print(“Dequeue: “, element)

Peek
frontElement = queue[0]
print(“Peek: “, frontElement)

isEmpty
isEmpty = not bool(queue)
print(“isEmpty: “, isEmpty)

Size
print(“Size: “, len(queue))

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