phpでqueueとstackを試す。
queue
先入先出し First In First Out。
入れた順番に取り出せる。
push/pop関数も使えるけどこれを使うとstackと同じ挙動になる。
$queue = new \SplQueue();
for($i = 0; $i < 10; $i++) {
$queue->enqueue($i);
}
while (!$queue->isEmpty()) {
$this->info($queue->dequeue());
}
0
1
2
3
4
5
6
7
8
9
stack
後入れ先出し Last In First Out
$stack = new \SplStack();
for($i = 0; $i < 10; $i++) {
$stack->push($i);
}
while (!$stack->isEmpty()) {
$this->info($stack->pop());
}
9
8
7
6
5
4
3
2
1
0