1 | <?php |
||
8 | abstract class ListAbstract implements ListInterface { |
||
9 | protected $size; |
||
10 | |||
11 | /** |
||
12 | * Insert a node in the specified list position. |
||
13 | * |
||
14 | * @param integer $index position |
||
15 | * @param mixed $data data to be saved |
||
16 | */ |
||
17 | public function insert($index, $data) { |
||
32 | |||
33 | /** |
||
34 | * Add a new node in the specified index. |
||
35 | * |
||
36 | * @param integer $index the position. |
||
37 | * @param mixed $data the data to be stored. |
||
38 | */ |
||
39 | protected abstract function insertAt($index, $data); |
||
40 | |||
41 | /** |
||
42 | * Add a new node in the specified index. |
||
43 | * |
||
44 | * @param mixed $data the data to be stored. |
||
45 | */ |
||
46 | protected abstract function insertEnd($data); |
||
47 | |||
48 | /** |
||
49 | * Inserts at the beginning of the list. |
||
50 | * |
||
51 | * @param mixed $data |
||
52 | */ |
||
53 | protected abstract function insertBeginning($data); |
||
54 | |||
55 | /** |
||
56 | * Removes all nodes of the list. It removes from the beginning. |
||
57 | */ |
||
58 | public function clear() { |
||
63 | |||
64 | /** |
||
65 | * Binds to count() method. This is equal to make $this->tree->size(). |
||
66 | * |
||
67 | * @return integer the tree size. 0 if it is empty. |
||
68 | */ |
||
69 | public function count() { |
||
72 | |||
73 | /** |
||
74 | * Returns the array size. |
||
75 | * |
||
76 | * @return int the length |
||
77 | */ |
||
78 | public function size() : int { |
||
81 | |||
82 | /** |
||
83 | * Checks if the list is empty. |
||
84 | * |
||
85 | * @return boolean true if is empty, else false. |
||
86 | */ |
||
87 | public function empty() : bool { |
||
90 | |||
91 | /** |
||
92 | * Adds at the end of the list new node containing |
||
93 | * the data to be stored. |
||
94 | * |
||
95 | * @param mixed $data The data |
||
96 | */ |
||
97 | public function push($data) { |
||
100 | |||
101 | /** |
||
102 | * Adds at the beginning a node in the list. |
||
103 | * |
||
104 | * @param mixed $data |
||
105 | * @return mixed the data stored. |
||
106 | */ |
||
107 | public function unshift($data) { |
||
110 | |||
111 | /** |
||
112 | * Deletes the first node of the list and returns it. |
||
113 | * |
||
114 | * @return mixed the data. |
||
115 | */ |
||
116 | public function shift() { |
||
119 | |||
120 | /** |
||
121 | * Removes and returns the last node in the list. |
||
122 | * |
||
123 | * @return mixed data in node. |
||
124 | */ |
||
125 | public function pop() { |
||
128 | |||
129 | /** |
||
130 | * Delete a node in the given position and returns it back. |
||
131 | * |
||
132 | * @param integer $index the position. |
||
133 | * @throws OutOfBoundsException if index is negative |
||
134 | * or is greater than the size of the list. |
||
135 | */ |
||
136 | public function delete($index) { |
||
158 | |||
159 | /** |
||
160 | * Deletes at the beginnig of the list and returns the data stored. |
||
161 | * |
||
162 | * @return mixed the data stored in the node. |
||
163 | */ |
||
164 | protected abstract function deleteBeginning(); |
||
165 | |||
166 | /** |
||
167 | * Deletes at the specified position and returns the data stored. |
||
168 | * |
||
169 | * @param integer $index the position. |
||
170 | * @return mixed the data stored in the node. |
||
171 | */ |
||
172 | protected abstract function deleteAt($index); |
||
173 | |||
174 | /** |
||
175 | * Deletes at the end of the list and returns the data stored. |
||
176 | * |
||
177 | * @return mixed the data stored in the node. |
||
178 | */ |
||
179 | protected abstract function deleteEnd(); |
||
180 | |||
181 | /** |
||
182 | * Converts/exports the list content into array type. |
||
183 | * |
||
184 | * @return array data stored in all nodes. |
||
185 | */ |
||
186 | public function toArray() : array { |
||
194 | } |