0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

php queue/stack試す

Posted at

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?