Completed
Push — master ( 46289f...c51b27 )
by Siro Díaz
01:28
created

ListAbstract::shift()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace DataStructures\Lists;
4
5
use DataStructures\Lists\Interfaces\ListInterface;
6
7
abstract class ListAbstract implements ListInterface {
8
    protected $size;
9
10
    /**
11
     * Binds to count() method. This is equal to make $this->tree->size().
12
     *
13
     * @return integer the tree size. 0 if it is empty.
14
     */
15
    public function count() {
16
        return $this->size;
17
    }
18
19
    /**
20
     * Returns the array size.
21
     *
22
     * @return int the length
23
     */
24
    public function size() : int {
25
        return $this->size;
26
    }
27
28
    /**
29
     * Checks if the list is empty.
30
     *
31
     * @return boolean true if is empty, else false.
32
     */
33
    public function empty() : bool {
34
        return $this->size === 0;
35
    }
36
37
    /**
38
     * Adds at the end of the list new node containing
39
     * the data to be stored.
40
     *
41
     * @param mixed $data The data
42
     */
43
    public function push($data) {
44
        $this->insert($this->size, $data);
45
    }
46
47
    /**
48
     * Adds at the beginning a node in the list.
49
     *
50
     * @param mixed $data
51
     * @return mixed the data stored.
52
     */
53
    public function unshift($data) {
54
        $this->insert(0, $data);
55
    }
56
57
    /**
58
     * Deletes the first node of the list and returns it.
59
     *
60
     * @return mixed the data.
61
     */
62
    public function shift() {
63
        return $this->delete(0);
64
    }
65
66
    /**
67
     * Removes and returns the last node in the list.
68
     *
69
     * @return mixed data in node.
70
     */
71
    public function pop() {
72
        return $this->delete($this->size - 1);
73
    }
74
}