} else { echo "stack is empty"; } } public function isEmpty() { if ($this->index == -1) { return true; } else { return false; } } public function first() { echo $this->stackArray[$this->index]; } public function last() { echo $this->stackArray[0]; } } $newStack = new Stack(); $newStack->push(2); $newStack->push(6); $newStack->pop(); $newStack->pop(); $newStack->pop(); $newStack->isEmpty(); $newStack->first(); $newStack->last(); $newStack->getElement(1);
$this->index--; return $element; } echo "There is no element in the quee array"; } public function isEmpty() { if ($this->index == -1) { return true; } else { return false; } } public function first() { return $this->queArray[$this->index]; } public function last() { return $this->queArray[0]; } } $muy = new Stack(array(3, 4, 7)); $myStack = new Stack(); $myStack->push(1); $myStack->push(4); echo $myStack->first(), "<br>"; echo $myStack->last(), "<br>"; echo $myStack->pop(), "<br>"; echo $myStack->pop(), "<br>"; $myStack->pop();