Horje
stack queue in python Code Example
stack queue in python
"""
Stack is a Last In First Out Data structure
It can be implemented using a list as illustrated belo
push <==> append, and pop <==> pop from list
"""
stack = ["John", "Elie", "Rami"]
# Push an item
stack.append("Wissam")
print(stack)

# Pop an item: removes the last item
print(stack.pop())

"""
Queue is a First In First Out Data structure
It can be implemented efficiently using a Deque
enqueue <==> append and dequeue <==> popleft
"""
from collections import deque
queue = deque(["Wissam", "John", "Elie"])
queue.append("Rami")
print(queue)

# popleft removes the first element in queue
print(queue.popleft())




Python

Related
full form of ram Code Example full form of ram Code Example
python aws s3 client Code Example python aws s3 client Code Example
no module named base45 windows Code Example no module named base45 windows Code Example
bail bond cowboys Code Example bail bond cowboys Code Example
how to do swapping in python without Code Example how to do swapping in python without Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7