Skip to content

Commit 39ed499

Browse files
committed
stack peek method fix
1 parent bc91613 commit 39ed499

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/Datastructure/Stackqueue/Stack.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,13 @@ protected function isValid(): bool {
9090
*
9191
*/
9292
public function peek() {
93-
if ($this->stack === null) {
93+
if (!$this->isValid()) {
9494
return null;
9595
}
96-
if ($this->stackSize() == 0) {
96+
if (0 === $this->stackSize()) {
9797
return null;
9898
}
99-
10099
$value = $this->stack[$this->stackSize() - 1];
101-
$this->pop();
102100
return $value;
103101
}
104102

0 commit comments

Comments
 (0)