-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperandStack.php
43 lines (35 loc) · 963 Bytes
/
OperandStack.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
<?php
class OperandStack
{
private $values = array(0);
// function __construct() {
// $this->values = array(0);
// }
public function peek()
{
if(sizeof($this->values)>0) {
return $this->values[sizeof($this->values)-1];
} else return 0;
}
public function top()
{
if(sizeof($this->values)>0) {
return $this->values[sizeof($this->values)-1];
}
}
public function replaceTop($value)
{
$this->pop();
array_push($this->values, $value);
}
public function push($value)
{
array_push($this->values, $value);
}
public function pop()
{
if(sizeof($this->values)>0)
array_pop($this->values);
}
}
?>