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 | /** |
||
41 | * Add a new node in the specified index. |
||
42 | * |
||
43 | * @param mixed $data the data to be stored. |
||
44 | */ |
||
45 | protected abstract function insertEnd($data); |
||
46 | |||
47 | /** |
||
48 | * Inserts at the beginning of the list. |
||
49 | * |
||
50 | * @param mixed $data |
||
51 | */ |
||
52 | protected abstract function insertBeginning($data); |
||
53 | |||
54 | /** |
||
55 | * Removes all nodes of the list. It removes from the beginning. |
||
56 | */ |
||
57 | public function clear() { |
||
62 | |||
63 | /** |
||
64 | * Binds to count() method. This is equal to make $this->tree->size(). |
||
65 | * |
||
66 | * @return integer the tree size. 0 if it is empty. |
||
67 | */ |
||
68 | public function count() { |
||
71 | |||
72 | /** |
||
73 | * Returns the array size. |
||
74 | * |
||
75 | * @return int the length |
||
76 | */ |
||
77 | public function size() : int { |
||
80 | |||
81 | /** |
||
82 | * Checks if the list is empty. |
||
83 | * |
||
84 | * @return boolean true if is empty, else false. |
||
85 | */ |
||
86 | public function empty() : bool { |
||
89 | |||
90 | /** |
||
91 | * Adds at the end of the list new node containing |
||
92 | * the data to be stored. |
||
93 | * |
||
94 | * @param mixed $data The data |
||
95 | */ |
||
96 | public function push($data) { |
||
99 | |||
100 | /** |
||
101 | * Adds at the beginning a node in the list. |
||
102 | * |
||
103 | * @param mixed $data |
||
104 | * @return mixed the data stored. |
||
105 | */ |
||
106 | public function unshift($data) { |
||
109 | |||
110 | /** |
||
111 | * Deletes the first node of the list and returns it. |
||
112 | * |
||
113 | * @return mixed the data. |
||
114 | */ |
||
115 | public function shift() { |
||
118 | |||
119 | /** |
||
120 | * Removes and returns the last node in the list. |
||
121 | * |
||
122 | * @return mixed data in node. |
||
123 | */ |
||
124 | public function pop() { |
||
127 | } |