|
C++ |
Rust |
Python |
Go |
Declaration |
queue<int> q; |
Implemented as VecDeque |
import queue
class Test
def __init__(self):
self.q = queue.Queue()
|
type test struct {
q []int //slice to work as queue
}
|
Front |
q.front() |
|
# get() = pop(). returns top
int front = self.q.get();
|
q[0]
|
Iterate Queue |
|
|
|
for i:=0; i < len(q); i++ {
q[i]
}
|
Push |
q.push(a) |
|
self.q.put(10)
|
q.append(x)
|
Pop |
q.pop() |
|
# get() = pop(). returns top
int front = self.q.get()
|
q = q[1:0] //Remove 1st element,ie top
|
Size |
q.size() |
|
self.q.qsize()
|
len(q)
|
Check empty |
!q.empty() |
|
self.q.empty()
|
if len(q) == 0 {
return true
}
|