1 | <?php |
||
7 | abstract class ListAbstract implements ListInterface { |
||
8 | protected $size; |
||
9 | |||
10 | /** |
||
11 | * Insert a node in the specified list position. |
||
12 | * |
||
13 | * @param integer $index position |
||
14 | * @param mixed $data data to be saved |
||
15 | */ |
||
16 | public function insert($index, $data) { |
||
31 | |||
32 | /** |
||
33 | * Add a new node in the specified index. |
||
34 | * |
||
35 | * @param integer $index the position. |
||
36 | * @param mixed $data the data to be stored. |
||
37 | */ |
||
38 | protected abstract function insertAt($index, $data); |
||
39 | |||
40 | protected abstract function insertEnd($data); |
||
41 | |||
42 | protected abstract function insertBeginning($data); |
||
43 | |||
44 | /** |
||
45 | * Binds to count() method. This is equal to make $this->tree->size(). |
||
46 | * |
||
47 | * @return integer the tree size. 0 if it is empty. |
||
48 | */ |
||
49 | public function count() { |
||
52 | |||
53 | /** |
||
54 | * Returns the array size. |
||
55 | * |
||
56 | * @return int the length |
||
57 | */ |
||
58 | public function size() : int { |
||
61 | |||
62 | /** |
||
63 | * Checks if the list is empty. |
||
64 | * |
||
65 | * @return boolean true if is empty, else false. |
||
66 | */ |
||
67 | public function empty() : bool { |
||
70 | |||
71 | /** |
||
72 | * Adds at the end of the list new node containing |
||
73 | * the data to be stored. |
||
74 | * |
||
75 | * @param mixed $data The data |
||
76 | */ |
||
77 | public function push($data) { |
||
80 | |||
81 | /** |
||
82 | * Adds at the beginning a node in the list. |
||
83 | * |
||
84 | * @param mixed $data |
||
85 | * @return mixed the data stored. |
||
86 | */ |
||
87 | public function unshift($data) { |
||
90 | |||
91 | /** |
||
92 | * Deletes the first node of the list and returns it. |
||
93 | * |
||
94 | * @return mixed the data. |
||
95 | */ |
||
96 | public function shift() { |
||
99 | |||
100 | /** |
||
101 | * Removes and returns the last node in the list. |
||
102 | * |
||
103 | * @return mixed data in node. |
||
104 | */ |
||
105 | public function pop() { |
||
108 | } |