-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
StackInterface.php
56 lines (48 loc) 路 1.16 KB
/
StackInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace Psl\DataStructure;
use Countable;
/**
* An interface representing a stack data structure ( LIFO ).
*
* @template T
*
* @see https://en.wikipedia.org/wiki/Stack_(abstract_data_type)
*/
interface StackInterface extends Countable
{
/**
* Adds an item to the stack.
*
* @param T $item
*/
public function push(mixed $item): void;
/**
* Retrieves, but does remove, the most recently added item that was not yet removed,
* or returns null if this queue is empty.
*
* @return null|T
*/
public function peek(): mixed;
/**
* Retrieves and removes the most recently added item that was not yet removed,
* or returns null if this queue is empty.
*
* @return null|T
*/
public function pull(): mixed;
/**
* Retrieve and removes the most recently added item that was not yet removed.
*
* @throws Exception\UnderflowException If the stack is empty.
*
* @return T
*/
public function pop(): mixed;
/**
* Count the items in the stack.
*
* @return int<0, max>
*/
public function count(): int;
}